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

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

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

e.t = h
e.q = i
a.t = b
d.t = h
i.t = d
i.q = l
h.t = b
m.t = h
l.t = d
l.q = i
n.t = k
n.q = i
b.t = a
k.t = b
assert b.t.t.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: A = None
        self.txt = txt

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

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

e.t = h
e.q = i
a.t = b
d.t = h
i.t = d
i.q = l
h.t = b
m.t = h
l.t = d
l.q = i
n.t = k
n.q = i
b.t = a
k.t = b
assert b.t.t.t.t.t.t.t.t.txt == "b"