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

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

j = A("j")
k = B("k")
f = A("f")
c = B("c")
m = B("m")
a = A("a")
d = A("d")
l = A("l")
g = B("g")
h = A("h")

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

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

j = A("j")
k = B("k")
f = A("f")
c = B("c")
m = B("m")
a = A("a")
d = A("d")
l = A("l")
g = B("g")
h = A("h")

j.t = d
k.z = g
f.t = d
c.z = m
m.z = c
a.t = j
d.t = f
l.t = a
g.z = c
h.t = l
assert c.z.z.z.z.z.txt == "m"