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

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

a = A("a")
j = B("j")
i = B("i")
f = A("f")
c = B("c")
m = B("m")
b = B("b")
d = B("d")

a.u = i
a.z = b
j.w = f
i.w = a
f.u = d
f.z = i
c.w = a
m.w = a
b.w = a
d.w = a
assert b.w.z.w.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: B = None
        self.txt = txt

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

a = A("a")
j = B("j")
i = B("i")
f = A("f")
c = B("c")
m = B("m")
b = B("b")
d = B("d")

a.u = i
a.z = b
j.w = f
i.w = a
f.u = d
f.z = i
c.w = a
m.w = a
b.w = a
d.w = a
assert b.w.z.w.z.w.txt == "a"