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

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

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

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

k.q = c
a.r = n
a.q = i
i.v = m
i.u = k
h.q = c
c.r = n
c.q = i
n.r = c
n.q = i
m.q = c
assert n.q.u.q.q.v.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

k.q = c
a.r = n
a.q = i
i.v = m
i.u = k
h.q = c
c.r = n
c.q = i
n.r = c
n.q = i
m.q = c
assert n.q.u.q.q.v.q.r.txt == "n"