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

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

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

a = A("a")
i = B("i")
n = C("n")
g = C("g")

a.u = i
i.o = n
n.o = i
n.q = g
n.y = a
g.o = i
g.q = n
g.y = a
assert i.o.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
n = C("n")
g = C("g")

a.u = i
i.o = n
n.o = i
n.q = g
n.y = a
g.o = i
g.q = n
g.y = a
assert i.o.y.u.txt == "i"