class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = 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.u: B = None
        self.s: B = None
        self.txt = txt

a = A("a")
l = B("l")
n = C("n")
m = A("m")
k = C("k")
i = B("i")
c = A("c")
b = B("b")

a.r = c
a.z = m
l.q = n
n.w = c
n.u = i
n.s = b
m.r = a
m.z = a
k.w = a
k.u = b
k.s = b
i.q = n
c.r = a
c.z = m
b.q = k
assert n.s.q.w.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = 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.u: B = None
        self.s: B = None
        self.txt = txt

a = A("a")
l = B("l")
n = C("n")
m = A("m")
k = C("k")
i = B("i")
c = A("c")
b = B("b")

a.r = c
a.z = m
l.q = n
n.w = c
n.u = i
n.s = b
m.r = a
m.z = a
k.w = a
k.u = b
k.s = b
i.q = n
c.r = a
c.z = m
b.q = k
assert n.s.q.w.z.r.txt == "a"