class A:
    def __init__(self, txt: str):
        self.u: 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.z: B = None
        self.x: A = None
        self.txt = txt

a = A("a")
l = B("l")
g = C("g")
k = A("k")

a.u = g
l.q = g
g.z = l
g.x = a
k.u = g
assert k.u.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: 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.z: B = None
        self.x: A = None
        self.txt = txt

a = A("a")
l = B("l")
g = C("g")
k = A("k")

a.u = g
l.q = g
g.z = l
g.x = a
k.u = g
assert k.u.z.q.txt == "g"