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

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

f = A("f")
h = B("h")
d = A("d")
n = B("n")
c = B("c")
m = B("m")
a = A("a")
j = B("j")

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

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

f = A("f")
h = B("h")
d = A("d")
n = B("n")
c = B("c")
m = B("m")
a = A("a")
j = B("j")

f.o = d
f.z = m
h.u = m
d.o = a
d.z = c
n.u = j
c.u = h
m.u = h
a.o = d
a.z = h
j.u = c
assert m.u.u.u.u.u.u.txt == "m"