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

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

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

g = A("g")
m = B("m")
k = C("k")
c = C("c")
n = B("n")

g.v = k
m.v = n
k.s = g
c.s = g
n.v = m
assert k.s.v.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
k = C("k")
c = C("c")
n = B("n")

g.v = k
m.v = n
k.s = g
c.s = g
n.v = m
assert k.s.v.s.txt == "g"