class A:
    def __init__(self, txt: str):
        self.t: A = 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")
j = A("j")
b = B("b")
e = A("e")
l = A("l")
a = A("a")
i = A("i")
n = B("n")

d.t = a
d.p = m
m.r = n
j.t = i
j.p = b
b.r = m
e.t = l
e.p = m
l.t = i
l.p = b
a.t = j
a.p = m
i.t = d
i.p = b
n.r = b
assert j.t.t.t.p.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = 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")
j = A("j")
b = B("b")
e = A("e")
l = A("l")
a = A("a")
i = A("i")
n = B("n")

d.t = a
d.p = m
m.r = n
j.t = i
j.p = b
b.r = m
e.t = l
e.p = m
l.t = i
l.p = b
a.t = j
a.p = m
i.t = d
i.p = b
n.r = b
assert j.t.t.t.p.r.r.r.r.txt == "n"