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

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

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

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

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

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

a.r = l
a.z = d
e.y = d
e.z = m
l.r = a
l.z = d
d.y = e
d.z = l
m.r = l
m.z = e
assert e.y.y.z.txt == "m"