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

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

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

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

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

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

l.r = m
l.p = m
a.z = m
a.y = d
d.z = b
d.y = a
f.r = d
f.p = b
m.z = a
m.y = d
b.z = m
b.y = a
assert m.y.z.y.txt == "a"