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

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

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

m = A("m")
b = B("b")
n = C("n")

m.w = n
b.z = m
b.q = n
n.v = m
assert n.v.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

m = A("m")
b = B("b")
n = C("n")

m.w = n
b.z = m
b.q = n
n.v = m
assert n.v.w.v.txt == "m"