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

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

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

n = A("n")
a = B("a")
g = C("g")
m = C("m")
k = B("k")
i = A("i")
f = A("f")

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

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

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

n = A("n")
a = B("a")
g = C("g")
m = C("m")
k = B("k")
i = A("i")
f = A("f")

n.z = m
a.t = f
a.x = k
g.y = f
g.t = m
g.q = i
m.y = n
m.q = n
m.t = g
k.t = i
k.x = a
i.z = g
f.z = g
assert a.x.x.t.z.txt == "g"