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

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

a = A("a")
l = B("l")
m = A("m")
b = B("b")

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

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

a = A("a")
l = B("l")
m = A("m")
b = B("b")

a.z = b
l.v = m
m.z = l
b.v = m
assert a.z.v.z.txt == "l"