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

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

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

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

a.t = k
k.u = a
g.z = a
g.v = a
g.w = k
assert k.u.t.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

a.t = k
k.u = a
g.z = a
g.v = a
g.w = k
assert k.u.t.u.txt == "a"