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

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

f = A("f")
c = B("c")
d = B("d")

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

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

f = A("f")
c = B("c")
d = B("d")

f.x = c
c.v = f
c.z = f
d.v = f
d.z = f
assert f.x.z.x.txt == "c"