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

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

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

a = A("a")
i = B("i")
m = C("m")

a.t = m
a.s = i
i.z = m
i.q = m
i.p = a
m.w = a
m.q = a
assert a.s.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.s: B = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
m = C("m")

a.t = m
a.s = i
i.z = m
i.q = m
i.p = a
m.w = a
m.q = a
assert a.s.q.q.txt == "a"