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

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

k = A("k")
c = B("c")
d = B("d")
h = A("h")
g = B("g")
m = A("m")
e = B("e")
i = B("i")
b = B("b")

k.p = m
c.t = e
d.t = g
h.p = k
g.t = i
m.p = k
e.t = c
i.t = d
b.t = d
assert i.t.t.t.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

k = A("k")
c = B("c")
d = B("d")
h = A("h")
g = B("g")
m = A("m")
e = B("e")
i = B("i")
b = B("b")

k.p = m
c.t = e
d.t = g
h.p = k
g.t = i
m.p = k
e.t = c
i.t = d
b.t = d
assert i.t.t.t.t.t.t.t.t.t.txt == "i"