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

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

n = A("n")
m = B("m")
g = B("g")
a = B("a")
c = A("c")
d = B("d")
h = A("h")
k = B("k")
j = A("j")
f = A("f")

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

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

n = A("n")
m = B("m")
g = B("g")
a = B("a")
c = A("c")
d = B("d")
h = A("h")
k = B("k")
j = A("j")
f = A("f")

n.t = a
m.x = k
m.p = k
g.x = d
g.p = k
a.x = g
a.p = d
c.t = g
d.x = m
d.p = m
h.t = a
k.x = a
k.p = g
j.t = d
f.t = m
assert m.p.x.x.x.x.x.txt == "k"