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

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

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

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

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

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

d.x = h
k.t = e
k.p = a
m.t = k
m.p = c
h.x = d
e.t = m
e.p = k
n.t = e
n.p = a
c.t = m
c.p = m
b.x = h
a.t = k
a.p = c
assert b.x.x.x.x.x.txt == "h"