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

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

a = A("a")
n = B("n")
j = A("j")
k = A("k")
l = A("l")
c = B("c")
d = B("d")
m = A("m")
i = B("i")
b = B("b")

a.r = c
n.p = b
j.r = d
k.r = d
l.r = d
c.p = d
d.p = i
m.r = i
i.p = d
b.p = c
assert m.r.p.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
j = A("j")
k = A("k")
l = A("l")
c = B("c")
d = B("d")
m = A("m")
i = B("i")
b = B("b")

a.r = c
n.p = b
j.r = d
k.r = d
l.r = d
c.p = d
d.p = i
m.r = i
i.p = d
b.p = c
assert m.r.p.p.p.p.p.p.p.txt == "d"