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

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

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

k.q = d
k.y = g
k.w = a
a.p = k
a.z = k
g.w = a
g.t = a
g.p = a
d.w = a
d.t = a
d.p = a
assert k.q.t.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.y: C = None
        self.w: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.w: B = None
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

k.q = d
k.y = g
k.w = a
a.p = k
a.z = k
g.w = a
g.t = a
g.p = a
d.w = a
d.t = a
d.p = a
assert k.q.t.p.y.txt == "g"