CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class Comb:
    def __init__(self, N):
        F = [1] * (N + 1)
        for i in range(N):
            F[i + 1] = (i + 1) * F[i] % mod

        self.d_inv = {}
        self.d_comb = {}
        self.F = F

    def inv(self, a):
        if a not in self.d_inv:
            self.d_inv[a] = pow(a, mod - 2, mod)
        return self.d_inv[a]

    def comb(self, a, b):
        if (a, b) not in self.d_comb:
            self.d_comb[(a, b)] = (self.F[a] * self.inv(self.F[a - b]) * self.inv(self.F[b])) % mod
            self.d_comb[(a, a - b)] = self.d_comb[(a, b)]
        return self.d_comb[(a, b)] 


def main():
    K = int(eval(input()))
    S = input().strip()

    F25 = [1] * (K + 1)
    F26 = [1] * (K + 1)
    for i in range(K):
        F25[i + 1] = (25 * F25[i]) % mod
        F26[i + 1] = (26 * F26[i]) % mod

    comb = Comb(K + len(S) + 1)

    res = 0
    for k in range(K + 1):
        res += ((F25[K - k] * F26[k]) % mod * comb.comb(K - k + len(S) - 1, len(S) - 1)) % mod
        res %= mod
     
    print(res)


if __name__ == "__main__":
    main()



# Optimized solution
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class Comb:
    def __init__(self, N):
        F = [1] * (N + 1)
        for i in range(N):
            F[i + 1] = (i + 1) * F[i] % mod

        self.d_inv = {}
        self.d_comb = {}
        self.F = F

    def inv(self, a):
        if a not in self.d_inv:
            self.d_inv[a] = pow(a, mod - 2, mod)
        return self.d_inv[a]

    def comb(self, a, b):
        if (a, b) not in self.d_comb:
            self.d_comb[(a, b)] = (self.F[a] * self.inv(self.F[a - b]) * self.inv(self.F[b])) % mod
            self.d_comb[(a, a - b)] = self.d_comb[(a, b)]
        return self.d_comb[(a, b)] 


def main():
    K = int(eval(input()))
    S = input().strip()

    F25 = [1] * (K + 2)
    F26 = [1] * (K + 2)
    T = [1] * (K + 2)
    for i in range(K + 1):
        F25[i + 1] = (25 * F25[i]) % mod
        F26[i + 1] = (26 * F26[i]) % mod
        if i != 0:
            T[i] = pow(i, mod - 2, mod)

    r = 1
    res = 0
    for k in range(K + 1):
        res += ((F25[k] * F26[K - k]) % mod * r) % mod
        r *= (len(S) - 1 + k + 1)
        r %= mod
        r *= T[k + 1]
        r %= mod
        res %= mod
     
    print(res)


if __name__ == "__main__":
    main()
# Original solution
import sys
import math
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(eval(input()))
    S = input().strip()

    MOD = 10 ** 9 + 7

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    def cmb(n, k, p):
        if (k < 0) or (n < k):
            return 0
        r = min(k, n - k)
        return fact[n] * factinv[k] * factinv[n - k] % p

    N = 10 ** 6 * 2
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    ans = 0
    for i in range(K + 1):
        if len(S) == 1:
            ans += pow(25, i, MOD) * pow(26, K - i, MOD)
        else:
            ans += pow(25, i, MOD) * cmb(i + len(S) - 1, len(S) - 1, MOD) * pow(26, K - i, MOD)

    print((ans % MOD))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import math
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(eval(input()))
    S = input().strip()

    MOD = 10 ** 9 + 7

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    def cmb(n, k, p):
        if (k < 0) or (n < k):
            return 0
        r = min(k, n - k)
        return fact[n] * factinv[k] * factinv[n - k] % p

    N = 10 ** 6 * 2
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    ans = 0
    a = 1
    b = pow(26, K, MOD)
    for i in range(K + 1):
        ans += a * cmb(i + len(S) - 1, len(S) - 1, MOD) * b
        a = a * 25 % MOD
        b = b * pow(26, MOD - 2, MOD) % MOD

    print((ans % MOD))


if __name__ == '__main__':
    main()
# Original solution
# coding: utf-8
import sys
from math import factorial

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def nCr(n,r):
    return (factorial(n) // factorial(r) // factorial(n - r))


def main():
    k = ni()
    s = ns()
    n = len(s)
    mod = 1000000007
    ans = 0
    tmp1 = factorial(n+k)%mod
    tmp2 = 1
    tmp3 = tmp1
    for m in range(n):
        ans += ((nCr(n+k,m)%mod)*pow(25,n+k-m,mod))%mod
    ans = pow(26,n+k,mod) - ans
    ans %= mod
    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    k = ni()
    s = ns()
    n = len(s)
    mod = 1000000007
    ans = 0
    inv25 = pow(25, mod-2, mod)
    tmp1 = 1
    tmp2 = pow(25,n+k,mod)
    for m in range(n):
        ans += (tmp1*tmp2)%mod
        ans %= mod
        tmp1 *= (n+k-m)*pow(m+1,mod-2,mod)
        tmp2 *= inv25
        tmp1 %= mod
        tmp2 %= mod
    ans = pow(26,n+k,mod) - ans
    ans %= mod
    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution


MOD = 10**9+7
factorial = [1]
inverse_factorial = [0]


def modpow(a, p):
    ans = 1
    while p:
        if p&1 == 1:
            ans = (ans*a)%MOD
        a = (a*a)%MOD
        p >>= 1
    return ans


def nCr(n, r):
    if r == 0 or r == n:
        return 1
    return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD


def init_nCr(max_n):
    for i in range(1, 2*max_n+1):
        f = (factorial[-1]*i)%MOD
        factorial.append(f)
        inv_f = modpow(f, MOD-2)
        inverse_factorial.append(inv_f)


def pow(b, p):
    ans = 1
    for _ in range(p):
        ans = (ans*b)%MOD
    return ans


def pow_list(b, p):
    ans = [1]
    for _ in range(p):
        ans.append(ans[-1]*b)
    return ans


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K = read_int()
    S = len(input().strip())
    init_nCr(K+S)
    T = pow(26, K+S)
    pow_25 = pow_list(25, K+S)
    for i in range(S):
        T = (T-nCr(K+S, i)*pow_25[K+S-i])%MOD
    return T


if __name__ == '__main__':
    print((solve()))


# Optimized solution


MOD = 10**9+7
factorial = [1]
inverse_factorial = [0]


def modpow(a, p):
    ans = 1
    while p:
        if p&1 == 1:
            ans = (ans*a)%MOD
        a = (a*a)%MOD
        p >>= 1
    return ans


def nCr(n, r):
    if r == 0 or r == n:
        return 1
    return (((factorial[n]*inverse_factorial[n-r])%MOD)*inverse_factorial[r])%MOD


def init_nCr(max_n):
    for i in range(1, max_n+1):
        f = (factorial[-1]*i)%MOD
        factorial.append(f)
        inv_f = modpow(f, MOD-2)
        inverse_factorial.append(inv_f)


def pow(b, p):
    ans = 1
    for _ in range(p):
        ans = (ans*b)%MOD
    return ans


def pow_list(b, p):
    ans = [1]
    for _ in range(p):
        ans.append((ans[-1]*b)%MOD)
    return ans


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    K = read_int()
    S = len(input().strip())
    init_nCr(K+S)
    T = pow(26, K+S)
    pow_25 = pow_list(25, K+S)
    for i in range(S):
        T = (T-(nCr(K+S, i)*pow_25[K+S-i])%MOD)%MOD
    return T


if __name__ == '__main__':
    print((solve()))
# Original solution
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

K = ri()
S = rs()

class CombMod:
    def __init__(self, N):
        self.fact = [1]
        self.rfact = [1]
        for i in range(1, N+1):
            self.fact.append(self.fact[i-1]*i % mod)
            self.rfact.append(pow(self.fact[i], mod-2, mod))

    def comb(self, n, k):
        return self.fact[n]*self.rfact[k]*self.rfact[n-k] % mod

N = len(S)
cm = CombMod(K+N)

ans = 0
for i in range(K+1):
	ans += cm.comb(K+N-i-1, N-1) * pow(26, i, mod) * pow(25, K-i, mod)
	ans = ans % mod
print(ans)


# Optimized solution
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

K = ri()
S = rs()

class CombMod:
    def __init__(self, N):
        self.fact = [1]
        self.rfact = [1]
        for i in range(1, N+1):
            self.fact.append(self.fact[i-1]*i % mod)
            self.rfact.append(pow(self.fact[i], mod-2, mod))

    def comb(self, n, k):
        return self.fact[n]*self.rfact[k]*self.rfact[n-k] % mod

N = len(S)
cm = CombMod(K+N)

pows = [1]
pows2 = [1]
p = 1
p2 = 1
for i in range(K+1):
	p = (p * 25) % mod
	p2 = (p2 * 26) % mod
	pows.append(p)
	pows2.append(p2)
#print(pows)
ans = 0
for i in range(K+1):
	#ans += cm.comb(K+N-i-1, N-1) * pow(26, i, mod) * pow(25, K-i, mod)
	ans += cm.comb(K+N-i-1, N-1) * pows2[i] * pows[K-i]
	ans = ans % mod
print(ans)
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = float('inf')
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    K = NI()
    S = SI()
    LS = len(S)

    f = [1]
    r = [1]
    c = 1
    for i in range(1, K + LS +1):
        c = (c * i) % MOD
        f.append(c)
        r.append(pow(c, MOD - 2, MOD))

    def comb(n, k):
        return (f[n] * r[k] * r[n - k]) % MOD

    ans = 0
    for i in range(K+1):
        ans = (ans + pow(25,i,MOD) * pow(26,K-i,MOD) * comb(i+LS-1,LS-1)) % MOD
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    K = NI()
    S = SI()
    LS = len(S)

    f = [1] * (K+LS)
    r = [1] * (K+LS)
    c = 1
    for i in range(1, K + LS):
        c = (c * i) % MOD
        f[i] = c
        r[i] = pow(c, MOD - 2, MOD)

    def comb(n, k):
        return (f[n] * r[k] * r[n - k]) % MOD

    ans = 0
    for i in range(K+1):
        ans = (ans + pow(25,i,MOD) * pow(26,K-i,MOD) * comb(i+LS-1,LS-1)) % MOD
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    K = NI()
    S = SI()
    LS = len(S)

    f = [1] * (K+LS)
    r = [1] * (K+LS)
    c = 1
    for i in range(1, K + LS):
        c = (c * i) % MOD
        f[i] = c
        r[i] = pow(c, MOD - 2, MOD)

    def comb(n, k):
        return (f[n] * r[k] * r[n - k]) % MOD

    ans = 0
    for i in range(K+1):
        ans = (ans + pow(25,i,MOD) * pow(26,K-i,MOD) * comb(i+LS-1,LS-1)) % MOD
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    K = NI()
    S = SI()
    LS = len(S)

    f = [0] * (K+LS)
    r = [0] * (K+LS)
    f[0] = 1
    r[0] = 1
    c = 1
    for i in range(1, K + LS):
        c = (c * i) % MOD
        f[i] = c
        r[i] = pow(c, MOD - 2, MOD)

    def comb(n, k):
        return (f[n] * r[k] * r[n - k]) % MOD

    ans = 0
    for i in range(K+1):
        ans = (ans + pow(25,i,MOD) * pow(26,K-i,MOD) * comb(i+LS-1,LS-1)) % MOD
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')

# ## COMBINATION (MOD) ###
N_MAX = 2*10**6  # 問題サイズに合わせて変えておく
MOD = 10**9 + 7

fac = [1, 1]  # 元テーブル
facinv = [1, 1]  # 逆元テーブル
inv = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N_MAX + 1):
    fac.append((fac[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    facinv.append((facinv[-1] * inv[-1]) % MOD)


def cmb(n, r):
    if (r < 0 or r > n):
        return 0
    # r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n - r] % MOD

# K 文字追加
ans = 0

ln = len(S)

for i in range(ln, ln+K+1):

    # pre
    p = i - 1
    p1 = cmb(p, ln - 1)
    p2 = pow(25, p - (ln - 1), MOD)

    # suf
    s = (ln + K) - i
    s2 = pow(26, s, MOD)

    ans += p1*p2*s2 % MOD
    ans %= MOD

    # print(p, p1,p2, s, s2)

print(ans)

# Optimized solution
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')

# ## COMBINATION (MOD) ###
N_MAX = 10**6  # 問題サイズに合わせて変えておく
MOD = 10**9 + 7

inv = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N_MAX + 2):
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)

# K 文字追加
ans = 0

ln = len(S)

p1 = 1
p2 = 1
s2 = pow(26, K, MOD)

for i in range(1, K + 2):

    ans += (p1 * p2 * s2) % MOD
    ans %= MOD

    # print(p1, p2, s2)

    # pre
    p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
    p2 = (p2 * 25) % MOD

    # suf
    s2 = (s2 * inv[26]) % MOD

print(ans)
# Original solution
import sys
readline = sys.stdin.readline

P = 10 ** 9 + 7
def mod_prod(a,b):
    return (a % P) * (b % P) % P

def mod_fact(a):
    ret = 1
    for i in range(a):
        ret = ret * (i + 1) % P
    return ret

def mod_pow(a, n):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * a % P
        a = a * a % P
        n = n >> 1
    return ret

def mod_div(a, b):
    b_inv = mod_pow(b, P - 2)
    return a * b_inv % P

def mod_comb(a,b):
    ret = 1
    b = min(b, a - b)
    for i in range(b):
        ret *= a - i
        ret %= P
    ret = mod_div(ret, mod_fact(b))
    return ret

def solve():
    K = int(readline())
    S = readline().rstrip()

    N = len(S)

    ans = 0
    for i in range(K + 1):
        ans += mod_pow(25, i) * mod_comb(i+N-1, i) * mod_pow(26, K-i)
        ans %= P
    print(ans)

solve()

# Optimized solution
import sys
readline = sys.stdin.readline

P = 10 ** 9 + 7
def mod_prod(a,b):
    return (a % P) * (b % P) % P

def mod_fact(a):
    ret = 1
    for i in range(a):
        ret = ret * (i + 1) % P
    return ret

def mod_pow(a, n):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * a % P
        a = a * a % P
        n = n >> 1
    return ret

def mod_div(a, b):
    b_inv = mod_pow(b, P - 2)
    return a * b_inv % P

def mod_comb(a,b):
    ret = 1
    b = min(b, a - b)
    for i in range(b):
        ret *= a - i
        ret %= P
    ret = mod_div(ret, mod_fact(b))
    return ret

def solve():
    K = int(readline())
    S = readline().rstrip()

    N = len(S)

    ans = 0
    cb = 1
    for i in range(K + 1):
        ans += mod_pow(25, i) * cb * mod_pow(26, K-i)
        cb = cb * mod_div(i + N - 1 + 1, i + 1) % P
        # mod_comb(i+N-1, i)
        ans %= P
    print(ans)

solve()
# Original solution
N,M,Q = list(map(int,input().split()))

a = list(map(int,input().split()))
q = list(map(int,input().split()))

t = [ 1 for i in range(N) ]
i = 0
for m in range(M):
    if a[m] % 2 == 1:
        s = -1
    else:
        s =  1
    aa = a[m]

    while aa > 0:
        i = (i + s) % N
        if t[i] == 1:
            aa -= 1
    t[i] = 0
    while True:
        i = (i + 1) % N
        if t[i] == 1:
            break;
for i in q:
    print((t[i]))



# Optimized solution
N,M,Q = list(map(int,input().split()))

a = list(map(int,input().split()))
q = list(map(int,input().split()))

t = [ i for i in range(N) ]
n = N
i = 0
for aa in a:
    if aa % 2 == 1:
        i = (i - aa) % n
    else:
        i = (i + aa) % n
    del t[i]
    n -= 1
    
for i in q:
    if i in t:
        print((1))
    else:
        print((0))
# Original solution
from bisect import bisect_left as bl

n, m, q = list(map(int, input().split()))
lst = [i for i in range(n)]
alst = list(map(int, input().split()))
ind = 0
for a in alst:
  if a % 2 == 0:
    ind += a
  else:
    ind -= a
  ind = ind % len(lst)
  lst.pop(ind)
  ind = ind % len(lst)

qlst = list(map(int, input().split()))
for q in qlst:
  qi = bl(lst, q)
  if qi >= len(lst):
    print((0))
  else:
    print((int(lst[qi] == q)))


# Optimized solution
from bisect import bisect_left as bl

n, m, q = list(map(int, input().split()))
lst = [i for i in range(n)]
alst = list(map(int, input().split()))
ind = 0
for a in alst:
  if a % 2 == 0:
    ind += a
  else:
    ind -= a
  ind = ind % len(lst)
  lst.pop(ind)
  ind = ind % len(lst)

qlst = list(map(int, input().split()))
for q in qlst:
  print((int(q in lst)))
# Original solution
import sys
f = sys.stdin

def is_odd(num):
    return num % 2

n,_,_ = list(map(int,f.readline().split()))#_は読み飛ばし
a = list(map(int, f.readline().split()))
q = list(map(int, f.readline().split()))

students = list(range(n))

pos = 0
for ai in a:
    pos += -ai if is_odd(ai) else ai
    pos %= len(students)
    students = students[:pos] + students[pos + 1:]

for qi in q:
    print((1 if qi in students else 0))

# Optimized solution
import sys
f = sys.stdin

def is_odd(num):
    return num % 2

n,_,_ = list(map(int,f.readline().split()))#_は読み飛ばし
a = list(map(int, f.readline().split()))
q = list(map(int, f.readline().split()))

s = list(range(n))

pos = 0
for ai in a:
    pos += -ai if is_odd(ai) else ai
    pos %= len(s)
    s.pop(pos)

for qi in q:
    print((1 if qi in s else 0))
# Original solution
n, m, _ = list(map(int, input().split()))
n0 = n
exem = [1] * n0
i = 0

for a in map(int, input().split()):
    is_even = not a & 1
    a %= n
    if is_even: a = n - a
    c = 0
    while a:
        c += 1
        if exem[i - c]:
            a -= 1
    exem[i - c] = 0
    i = (i - c + 1) % n0
    n -= 1

for q in map(int, input().split()):
    print((exem[q]))

# Optimized solution
n, m, _ = list(map(int, input().split()))
exem = list(range(n))
i = 0

for a in map(int, input().split()):
    is_odd = a & 1
    i += -a if a & 1 else a
    i %= n
    exem.pop(i)
    n -= 1

for q in map(int, input().split()):
    print((int(q in exem)))
# Original solution
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0301
WA
"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def main(args):
    # members = deque(list(range(10)))
    # numbers = [2, 6, 5, 18, 3]
    # queries = [3, 0, 5]

    N, M, Q = list(map(int, input().split(' ')))
    members = deque(list(range(N)))
    numbers = [int(x) for x in input().split(' ')]
    queries = [int(x) for x in input().split(' ')]


    for n in numbers:
        if n % 2 == 0:
            n = n % N
            members.rotate(-n)
            members.popleft()
        else:
            n = n % N
            members.rotate(n)
            members.popleft()
        N -= 1


    for q in queries:
        ans = 1 if q in members else 0
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

# Optimized solution
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0301

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def main(args):
    # members = deque(list(range(10)))
    # numbers = [2, 6, 5, 18, 3]
    # queries = [3, 0, 5]

    N, M, Q = list(map(int, input().split(' ')))
    members = deque(list(range(N)))
    numbers = [int(x) for x in input().split(' ')]
    queries = [int(x) for x in input().split(' ')]

    for n in numbers:
        if n % 2 == 0:
            # n = n % N
            members.rotate(-n)
            members.popleft()
        else:
            # n = n % N
            members.rotate(n)
            members.popleft()
        N -= 1

    for q in queries:
        ans = 1 if q in members else 0
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
# Original solution
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

H, W, *AB = list(map(int, read().split()))
AB_list = [(-1,-1)]
for i in range(H):
    a, b = AB[2*i], AB[2*i+1]
    AB_list.append((a,b))

min_list = [INF] * (H+3)
MAP = [[INF] * (W + 2) for _ in range(H + 3)]

def bfs(start):
    queue = deque([(start + (0,))])
    while queue:
        ci,cj, count = queue.popleft()
        if min_list[ci] > count:
            min_list[ci] = count

        if ci == H+1:continue
        a, b = AB_list[ci]

        if a <= cj <= b:
            if b + 1 <= W:
                queue.append((ci+1, b + 1, count + b- cj + 2))

        elif ci + 1 <= H+1:
            queue.append((ci+1, cj, count + 1))


def run():
    for j in range(1, W+1):
        bfs((1, j))

    for v in min_list[2:-1]:
        if v == INF:
            print((-1))
        else:
            print(v)

    #for m in MAP:
    #    print(m)




if __name__ == "__main__":
    run()

# Optimized solution
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

H, W, *AB = list(map(int, read().split()))
AB_list = [(-1,-1)]
for i in range(H):
    a, b = AB[2*i], AB[2*i+1]
    AB_list.append((a,b))

min_list = [INF] * (H+3)
MAP = [[INF] * (W + 2) for _ in range(H + 3)]

def bfs(start):
    queue = deque([(start + (0,))])
    while queue:
        ci,cj, count = queue.popleft()
        if min_list[ci] > count:
            min_list[ci] = count

        if ci == H+1:continue
        a, b = AB_list[ci]

        if a <= cj <= b:
            if b + 1 <= W:
                queue.append((ci+1, b + 1, count + b- cj + 2))

        elif ci + 1 <= H+1:
            queue.append((ci+1, cj, count + 1))


def run():
    a1, b1 = AB_list[1]
    for j in range(1, W+1):
        if a1 <= j <= b1:continue
        bfs((1, j))

    for v in min_list[2:-1]:
        if v == INF:
            print((-1))
        else:
            print(v)

    #for m in MAP:
    #    print(m)




if __name__ == "__main__":
    run()