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

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.u: C = None
        self.t: 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")
e = C("e")
c = A("c")
b = C("b")
g = A("g")

k.q = g
i.q = c
i.t = c
i.u = e
e.y = i
c.q = g
b.y = i
g.q = k
assert g.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.u: C = None
        self.t: 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")
e = C("e")
c = A("c")
b = C("b")
g = A("g")

k.q = g
i.q = c
i.t = c
i.u = e
e.y = i
c.q = g
b.y = i
g.q = k
assert g.q.q.q.q.txt == "g"