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

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

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

m = A("m")
i = B("i")
e = C("e")
a = B("a")
c = A("c")
j = C("j")
g = B("g")

m.v = g
i.r = c
i.z = e
e.q = i
e.s = c
a.r = c
a.z = j
c.v = a
j.q = a
j.s = c
g.r = c
g.z = e
assert e.q.r.v.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

m = A("m")
i = B("i")
e = C("e")
a = B("a")
c = A("c")
j = C("j")
g = B("g")

m.v = g
i.r = c
i.z = e
e.q = i
e.s = c
a.r = c
a.z = j
c.v = a
j.q = a
j.s = c
g.r = c
g.z = e
assert e.q.r.v.r.v.txt == "a"