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

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

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

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

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

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

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

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

g.q = i
g.z = n
n.u = g
i.u = n
assert n.u.q.u.txt == "n"