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

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

l = A("l")
g = B("g")
c = B("c")
m = A("m")
h = A("h")
i = B("i")
e = B("e")
j = A("j")
a = B("a")

l.q = m
g.t = h
c.t = l
m.q = h
h.q = m
i.t = m
e.t = h
j.q = l
a.t = h
assert m.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

l = A("l")
g = B("g")
c = B("c")
m = A("m")
h = A("h")
i = B("i")
e = B("e")
j = A("j")
a = B("a")

l.q = m
g.t = h
c.t = l
m.q = h
h.q = m
i.t = m
e.t = h
j.q = l
a.t = h
assert m.q.q.q.q.q.txt == "h"