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

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

c = A("c")
k = B("k")
j = A("j")
m = B("m")
e = B("e")
f = B("f")
d = A("d")
l = A("l")

c.t = m
c.x = j
k.z = m
j.t = e
j.x = c
m.z = k
e.z = f
f.z = m
d.t = f
d.x = c
l.t = f
l.x = d
assert m.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: A = None
        self.txt = txt

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

c = A("c")
k = B("k")
j = A("j")
m = B("m")
e = B("e")
f = B("f")
d = A("d")
l = A("l")

c.t = m
c.x = j
k.z = m
j.t = e
j.x = c
m.z = k
e.z = f
f.z = m
d.t = f
d.x = c
l.t = f
l.x = d
assert m.z.z.z.z.txt == "m"