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

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

l = A("l")
n = B("n")
m = A("m")
k = B("k")

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

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

l = A("l")
n = B("n")
m = A("m")
k = B("k")

l.v = k
l.r = m
n.v = k
n.z = l
m.v = k
m.r = l
k.v = n
k.z = l
assert k.v.v.v.txt == "n"