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

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

d = A("d")
g = B("g")
a = C("a")
f = A("f")
e = B("e")
n = B("n")
i = C("i")

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

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

d = A("d")
g = B("g")
a = C("a")
f = A("f")
e = B("e")
n = B("n")
i = C("i")

d.x = i
g.y = e
g.q = e
a.x = g
a.z = i
f.x = i
e.y = g
e.q = g
n.y = e
n.q = g
i.x = n
i.z = a
assert a.x.q.y.q.q.txt == "g"