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

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

d = A("d")
m = B("m")
i = B("i")
e = A("e")
b = A("b")
a = B("a")
g = A("g")
c = B("c")
l = A("l")

d.q = i
m.u = c
i.u = a
e.q = c
b.q = m
a.u = i
g.q = a
c.u = m
l.q = c
assert c.u.u.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
i = B("i")
e = A("e")
b = A("b")
a = B("a")
g = A("g")
c = B("c")
l = A("l")

d.q = i
m.u = c
i.u = a
e.q = c
b.q = m
a.u = i
g.q = a
c.u = m
l.q = c
assert c.u.u.u.u.u.u.u.u.u.txt == "m"