import numpy as np import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) mod = 10 ** 9 + 7 def convolve(A, B): n = len(A) + len(B) - 1 fftlen = 1 << (n-1).bit_length() fa = np.fft.rfft(A, fftlen) fb = np.fft.rfft(B, fftlen) inv = (np.fft.irfft(fa * fb, fftlen) + 0.5).astype(np.int64) return inv[:n] def mod_convolve_10(A, B, mod): a1, a2 = np.divmod(A, 1 << 20) a2, a3 = np.divmod(a2, 1 << 10) b1, b2 = np.divmod(B, 1 << 20) b2, b3 = np.divmod(b2, 1 << 10) x = convolve(a1, b1) % mod y = convolve(a2, b2) % mod z = convolve(a3, b3) % mod xy = (convolve(a1 + a2, b1 + b2) - (x + y)) % mod yz = (convolve(a2 + a3, b2 + b3) - (y + z)) % mod zx = (convolve(a3 + a1, b3 + b1) - (z + x)) % mod res = ((((x << 20) % mod) << 20) + (((xy << 20) % mod) << 10) + ((y + zx) << 20) + (yz << 10) % mod + z) % mod return res p = int(input()) Q = int(input()) query = np.array([input() for _ in range(Q)], dtype=np.intc) U = 2 * 10 ** 6 A = [0, 1] for _ in range(2, U+1): A.append((p * A[-1] + A[-2]) % mod) A = np.array(A, dtype=np.int64) B = mod_convolve_10(A, A, mod) ans = B[query - 2] print(*ans, sep="\n")