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

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

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

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

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

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

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

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

g.z = k
g.x = k
k.q = a
k.w = a
k.y = g
a.v = k
a.q = k
b.v = k
b.q = k
d.v = k
d.q = k
assert k.y.z.w.q.txt == "k"