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

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

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

a = A("a")
k = B("k")
n = C("n")

a.t = n
k.q = n
n.w = a
n.v = a
assert a.t.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

a = A("a")
k = B("k")
n = C("n")

a.t = n
k.q = n
n.w = a
n.v = a
assert a.t.w.t.txt == "n"