class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: 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.s: B = None
        self.txt = txt

g = A("g")
e = B("e")
i = C("i")
l = A("l")
k = C("k")

g.v = l
g.q = k
e.q = i
i.s = e
l.v = g
l.q = k
k.s = e
assert g.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: 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.s: B = None
        self.txt = txt

g = A("g")
e = B("e")
i = C("i")
l = A("l")
k = C("k")

g.v = l
g.q = k
e.q = i
i.s = e
l.v = g
l.q = k
k.s = e
assert g.v.v.v.v.txt == "g"