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

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

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

f = A("f")
m = B("m")
d = C("d")

f.v = d
m.q = f
d.v = f
d.z = f
d.r = m
assert m.q.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

f = A("f")
m = B("m")
d = C("d")

f.v = d
m.q = f
d.v = f
d.z = f
d.r = m
assert m.q.v.v.txt == "f"