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

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

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

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

a.z = m
k.q = m
g.w = e
b.z = g
m.w = e
e.z = m
f.z = g
d.q = m
assert a.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

a.z = m
k.q = m
g.w = e
b.z = g
m.w = e
e.z = m
f.z = g
d.q = m
assert a.z.w.z.txt == "m"