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

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

f = A("f")
g = B("g")
a = B("a")
e = A("e")
i = B("i")
d = A("d")
k = B("k")
n = A("n")
l = A("l")

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

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

f = A("f")
g = B("g")
a = B("a")
e = A("e")
i = B("i")
d = A("d")
k = B("k")
n = A("n")
l = A("l")

f.q = a
g.t = k
a.t = k
e.q = i
i.t = k
d.q = a
k.t = i
n.q = i
l.q = i
assert k.t.t.t.t.t.t.t.t.t.txt == "i"