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

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

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

k = A("k")
i = B("i")
h = C("h")
g = C("g")
m = C("m")

k.t = m
i.v = k
h.y = i
g.y = i
m.y = i
assert m.y.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

k = A("k")
i = B("i")
h = C("h")
g = C("g")
m = C("m")

k.t = m
i.v = k
h.y = i
g.y = i
m.y = i
assert m.y.v.t.txt == "m"