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

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

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

a = A("a")
i = B("i")
k = C("k")
d = B("d")
g = B("g")

a.q = k
i.t = a
i.x = a
i.u = d
k.z = g
d.t = a
d.x = a
d.u = g
g.t = a
g.x = a
g.u = d
assert g.x.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
k = C("k")
d = B("d")
g = B("g")

a.q = k
i.t = a
i.x = a
i.u = d
k.z = g
d.t = a
d.x = a
d.u = g
g.t = a
g.x = a
g.u = d
assert g.x.q.z.txt == "g"