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

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

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

j = A("j")
b = B("b")
d = C("d")
i = B("i")
m = A("m")
n = C("n")
e = A("e")
g = C("g")
a = A("a")
k = B("k")

j.q = b
j.s = e
b.s = g
d.q = n
i.s = n
m.q = i
m.s = a
n.q = g
e.q = k
e.s = j
g.q = n
a.q = b
a.s = j
k.s = n
assert k.s.q.q.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: A = None
        self.txt = txt

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

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

j = A("j")
b = B("b")
d = C("d")
i = B("i")
m = A("m")
n = C("n")
e = A("e")
g = C("g")
a = A("a")
k = B("k")

j.q = b
j.s = e
b.s = g
d.q = n
i.s = n
m.q = i
m.s = a
n.q = g
e.q = k
e.s = j
g.q = n
a.q = b
a.s = j
k.s = n
assert k.s.q.q.q.q.q.q.q.q.q.txt == "g"