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

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

b = A("b")
j = B("j")
c = A("c")
f = A("f")
d = B("d")
k = B("k")
m = A("m")
l = A("l")

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

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

b = A("b")
j = B("j")
c = A("c")
f = A("f")
d = B("d")
k = B("k")
m = A("m")
l = A("l")

b.p = f
b.r = j
j.y = d
c.p = l
c.r = k
f.p = m
f.r = d
d.y = j
k.y = d
m.p = f
m.r = d
l.p = m
l.r = j
assert m.p.r.y.y.y.y.txt == "d"