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

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

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

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

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

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

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