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

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

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

e.t = f
e.r = f
k.q = f
g.q = c
m.t = k
m.r = g
f.q = k
l.t = g
l.r = k
h.t = f
h.r = k
c.q = g
assert c.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: B = None
        self.txt = txt

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

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

e.t = f
e.r = f
k.q = f
g.q = c
m.t = k
m.r = g
f.q = k
l.t = g
l.r = k
h.t = f
h.r = k
c.q = g
assert c.q.q.q.q.q.txt == "g"