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

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

d = A("d")
h = B("h")
e = B("e")
a = B("a")
l = A("l")
b = A("b")
m = A("m")

d.u = m
h.o = a
h.t = a
e.o = a
e.t = a
a.o = h
a.t = h
l.u = b
b.u = l
m.u = d
assert d.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

d = A("d")
h = B("h")
e = B("e")
a = B("a")
l = A("l")
b = A("b")
m = A("m")

d.u = m
h.o = a
h.t = a
e.o = a
e.t = a
a.o = h
a.t = h
l.u = b
b.u = l
m.u = d
assert d.u.u.u.u.u.u.u.txt == "m"