class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

d = A("d")
n = B("n")
k = A("k")
f = B("f")
c = A("c")
b = A("b")

d.u = f
n.x = b
n.p = c
k.u = n
f.x = d
f.p = b
c.u = f
b.u = f
assert c.u.x.u.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

d = A("d")
n = B("n")
k = A("k")
f = B("f")
c = A("c")
b = A("b")

d.u = f
n.x = b
n.p = c
k.u = n
f.x = d
f.p = b
c.u = f
b.u = f
assert c.u.x.u.x.u.txt == "f"