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

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

m = A("m")
a = B("a")
n = A("n")
d = B("d")
l = A("l")
i = A("i")

m.r = l
m.z = n
a.o = i
n.r = m
n.z = i
d.o = l
l.r = m
l.z = i
i.r = n
i.z = m
assert l.z.z.r.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = None
        self.txt = txt

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

m = A("m")
a = B("a")
n = A("n")
d = B("d")
l = A("l")
i = A("i")

m.r = l
m.z = n
a.o = i
n.r = m
n.z = i
d.o = l
l.r = m
l.z = i
i.r = n
i.z = m
assert l.z.z.r.r.z.txt == "n"