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

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

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

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

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

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

d.p = c
h.t = c
m.t = c
b.p = d
k.p = d
a.t = k
l.p = k
c.p = b
i.t = d
assert k.p.p.p.p.p.p.p.txt == "d"