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

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

l = A("l")
n = B("n")
i = A("i")
m = A("m")
g = A("g")

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

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

l = A("l")
n = B("n")
i = A("i")
m = A("m")
g = A("g")

l.z = m
l.r = n
n.s = i
n.z = g
i.z = l
i.r = n
m.z = g
m.r = n
g.z = m
g.r = n
assert i.z.r.z.r.txt == "n"