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

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

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

n = A("n")
c = B("c")
d = C("d")
j = B("j")
m = C("m")
h = C("h")
b = C("b")
k = A("k")
f = C("f")
e = C("e")

n.s = b
c.q = j
c.s = j
d.y = k
d.p = c
d.x = n
j.q = c
j.s = c
m.y = n
m.x = n
m.p = j
h.y = k
h.p = c
h.x = n
b.y = k
b.p = j
b.x = n
k.s = d
f.y = k
f.p = j
f.x = n
e.y = n
e.p = j
e.x = k
assert d.p.s.q.s.s.q.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

n = A("n")
c = B("c")
d = C("d")
j = B("j")
m = C("m")
h = C("h")
b = C("b")
k = A("k")
f = C("f")
e = C("e")

n.s = b
c.q = j
c.s = j
d.y = k
d.p = c
d.x = n
j.q = c
j.s = c
m.y = n
m.x = n
m.p = j
h.y = k
h.p = c
h.x = n
b.y = k
b.p = j
b.x = n
k.s = d
f.y = k
f.p = j
f.x = n
e.y = n
e.p = j
e.x = k
assert d.p.s.q.s.s.q.s.s.s.s.txt == "j"