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

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

n = A("n")
i = B("i")
m = A("m")
g = A("g")
h = B("h")
d = A("d")
l = A("l")
c = B("c")

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

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

n = A("n")
i = B("i")
m = A("m")
g = A("g")
h = B("h")
d = A("d")
l = A("l")
c = B("c")

n.r = c
n.z = l
i.o = n
i.z = n
m.r = i
m.z = d
g.r = h
g.z = l
h.o = g
h.z = m
d.r = h
d.z = l
l.r = c
l.z = n
c.o = d
c.z = m
assert i.o.z.z.z.txt == "l"