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

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

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

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

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

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

n.t = d
n.p = h
a.o = h
m.t = a
m.p = i
h.t = e
h.p = m
i.t = a
i.p = m
b.t = d
b.p = h
d.o = b
e.o = h
assert m.p.p.p.p.txt == "m"