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

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

d = A("d")
m = B("m")
l = B("l")
f = B("f")
h = A("h")
e = A("e")
a = A("a")
b = A("b")
g = A("g")

d.t = f
d.p = l
m.r = l
l.r = m
f.r = m
h.t = l
h.p = l
e.t = l
e.p = l
a.t = l
a.p = f
b.t = f
b.p = m
g.t = l
g.p = f
assert b.t.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
l = B("l")
f = B("f")
h = A("h")
e = A("e")
a = A("a")
b = A("b")
g = A("g")

d.t = f
d.p = l
m.r = l
l.r = m
f.r = m
h.t = l
h.p = l
e.t = l
e.p = l
a.t = l
a.p = f
b.t = f
b.p = m
g.t = l
g.p = f
assert b.t.r.r.r.r.r.r.r.txt == "m"