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

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

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

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

d.z = a
d.w = k
g.v = m
g.u = m
g.q = a
a.o = k
m.z = a
m.w = k
k.v = d
k.u = d
k.q = a
c.z = a
c.w = g
assert d.w.v.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.w: B = None
        self.txt = txt

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

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

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

d.z = a
d.w = k
g.v = m
g.u = m
g.q = a
a.o = k
m.z = a
m.w = k
k.v = d
k.u = d
k.q = a
c.z = a
c.w = g
assert d.w.v.z.o.txt == "k"