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

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

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

m = A("m")
a = B("a")
l = C("l")
g = C("g")
e = A("e")

m.s = a
m.z = a
m.q = e
a.o = l
a.r = l
a.p = e
l.u = a
g.u = a
e.s = a
e.z = a
e.q = m
assert m.q.q.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.z: B = None
        self.q: A = None
        self.txt = txt

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

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

m = A("m")
a = B("a")
l = C("l")
g = C("g")
e = A("e")

m.s = a
m.z = a
m.q = e
a.o = l
a.r = l
a.p = e
l.u = a
g.u = a
e.s = a
e.z = a
e.q = m
assert m.q.q.q.s.txt == "a"