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

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

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

c.z = n
d.z = b
d.u = c
b.z = d
b.u = c
n.z = c
assert b.z.u.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

c.z = n
d.z = b
d.u = c
b.z = d
b.u = c
n.z = c
assert b.z.u.z.z.txt == "c"