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

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

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

n = A("n")
b = B("b")
g = C("g")
e = B("e")
i = C("i")

n.u = i
b.z = i
b.p = e
b.q = n
g.o = n
g.u = i
g.w = e
e.z = i
e.p = b
e.q = n
i.o = n
i.u = g
i.w = e
assert b.q.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

n = A("n")
b = B("b")
g = C("g")
e = B("e")
i = C("i")

n.u = i
b.z = i
b.p = e
b.q = n
g.o = n
g.u = i
g.w = e
e.z = i
e.p = b
e.q = n
i.o = n
i.u = g
i.w = e
assert b.q.u.o.txt == "n"