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

j = A("j")
a = B("a")
k = A("k")
e = B("e")
b = B("b")
g = A("g")
m = A("m")
i = A("i")
c = A("c")

j.z = m
a.z = b
a.u = c
k.z = g
e.z = a
e.u = c
b.z = e
b.u = i
g.z = m
m.z = g
i.z = k
c.z = j
assert j.z.z.z.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

j = A("j")
a = B("a")
k = A("k")
e = B("e")
b = B("b")
g = A("g")
m = A("m")
i = A("i")
c = A("c")

j.z = m
a.z = b
a.u = c
k.z = g
e.z = a
e.u = c
b.z = e
b.u = i
g.z = m
m.z = g
i.z = k
c.z = j
assert j.z.z.z.z.z.txt == "m"