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

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

k = A("k")
b = B("b")
i = A("i")

k.z = b
b.z = i
b.v = k
i.z = b
assert i.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.z: A = None
        self.v: A = None
        self.txt = txt

k = A("k")
b = B("b")
i = A("i")

k.z = b
b.z = i
b.v = k
i.z = b
assert i.z.v.z.txt == "b"