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

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

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

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

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

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

c.z = f
e.u = f
f.u = k
h.z = e
l.z = f
j.u = e
k.u = f
d.z = f
m.z = j
assert d.z.u.u.u.u.u.u.txt == "f"