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

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

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

n = A("n")
k = B("k")
m = C("m")
a = C("a")
l = B("l")
e = A("e")

n.r = e
k.q = e
k.s = l
m.z = l
m.v = e
a.z = k
a.v = n
l.q = n
l.s = k
e.r = n
assert l.q.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
m = C("m")
a = C("a")
l = B("l")
e = A("e")

n.r = e
k.q = e
k.s = l
m.z = l
m.v = e
a.z = k
a.v = n
l.q = n
l.s = k
e.r = n
assert l.q.r.r.txt == "n"