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

h = A("h")
c = B("c")
n = C("n")
k = C("k")
e = B("e")
d = A("d")
g = A("g")
f = B("f")
i = C("i")
a = C("a")

h.r = c
c.q = n
n.v = f
n.q = d
k.v = f
k.q = g
e.q = k
d.r = f
g.r = c
f.q = i
i.v = e
i.q = g
a.v = f
a.q = h
assert n.q.r.q.q.r.q.q.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = 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.v: B = None
        self.q: A = None
        self.txt = txt

h = A("h")
c = B("c")
n = C("n")
k = C("k")
e = B("e")
d = A("d")
g = A("g")
f = B("f")
i = C("i")
a = C("a")

h.r = c
c.q = n
n.v = f
n.q = d
k.v = f
k.q = g
e.q = k
d.r = f
g.r = c
f.q = i
i.v = e
i.q = g
a.v = f
a.q = h
assert n.q.r.q.q.r.q.q.r.q.q.txt == "g"