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

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

d = A("d")
l = B("l")
j = A("j")
m = A("m")
a = A("a")

d.r = a
d.p = a
l.z = d
l.x = m
j.r = a
j.p = a
m.r = j
m.p = a
a.r = m
a.p = m
assert m.p.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
j = A("j")
m = A("m")
a = A("a")

d.r = a
d.p = a
l.z = d
l.x = m
j.r = a
j.p = a
m.r = j
m.p = a
a.r = m
a.p = m
assert m.p.p.r.txt == "j"