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

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

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

d = A("d")
g = B("g")
l = C("l")
k = B("k")
f = C("f")
b = A("b")
e = A("e")
n = B("n")
a = B("a")

d.s = f
d.r = g
d.q = e
g.q = n
g.v = k
l.v = k
l.r = d
l.x = e
k.q = a
k.v = n
f.v = a
f.r = b
f.x = d
b.s = f
b.r = k
b.q = e
e.s = f
e.r = k
e.q = b
n.q = a
n.v = g
a.q = n
a.v = g
assert n.v.v.q.q.v.v.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.r: B = None
        self.q: A = None
        self.txt = txt

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

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

d = A("d")
g = B("g")
l = C("l")
k = B("k")
f = C("f")
b = A("b")
e = A("e")
n = B("n")
a = B("a")

d.s = f
d.r = g
d.q = e
g.q = n
g.v = k
l.v = k
l.r = d
l.x = e
k.q = a
k.v = n
f.v = a
f.r = b
f.x = d
b.s = f
b.r = k
b.q = e
e.s = f
e.r = k
e.q = b
n.q = a
n.v = g
a.q = n
a.v = g
assert n.v.v.q.q.v.v.q.q.txt == "n"