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

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

a = A("a")
f = B("f")
g = B("g")
d = A("d")
e = B("e")
c = B("c")
n = B("n")

a.w = d
a.z = d
f.u = n
g.u = c
d.w = a
d.z = a
e.u = f
c.u = n
n.u = c
assert e.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.z: A = None
        self.txt = txt

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

a = A("a")
f = B("f")
g = B("g")
d = A("d")
e = B("e")
c = B("c")
n = B("n")

a.w = d
a.z = d
f.u = n
g.u = c
d.w = a
d.z = a
e.u = f
c.u = n
n.u = c
assert e.u.u.u.u.u.u.u.txt == "c"