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

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

j = A("j")
f = B("f")
a = B("a")

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

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

j = A("j")
f = B("f")
a = B("a")

j.v = f
f.v = j
f.z = j
a.v = j
a.z = j
assert f.z.v.z.txt == "j"