#include using namespace std; using ll = long long; using ull = unsigned long long; using i128 = __int128_t; using pii = pair; using pll = pair; template using vec = vector; template using vvec = vector>; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) constexpr char ln = '\n'; istream& operator>>(istream& is, __int128_t& x) { x = 0; string s; is >> s; int n = int(s.size()), it = 0; if (s[0] == '-') it++; for (; it < n; it++) x = (x * 10 + s[it] - '0'); if (s[0] == '-') x = -x; return is; } ostream& operator<<(ostream& os, __int128_t x) { if (x == 0) return os << 0; if (x < 0) os << '-', x = -x; deque deq; while (x) deq.emplace_front(x % 10), x /= 10; for (int e : deq) os << e; return os; } template ostream& operator<<(ostream& os, const pair& p) { return os << "(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& os, const vector& v) { os << "{"; for (int i = 0; i < int(v.size()); i++) { if (i) os << ", "; os << v[i]; } return os << "}"; } template inline int SZ(const Container& v) { return int(v.size()); } template inline void UNIQUE(vector& v) { v.erase(unique(v.begin(), v.end()), v.end()); } template inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return true; } return false; } inline int topbit(ull x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); } inline int botbit(ull x) { return x == 0 ? 64 : __builtin_ctzll(x); } inline int popcount(ull x) { return __builtin_popcountll(x); } inline int kthbit(ull x, int k) { return (x >> k) & 1; } inline constexpr long long TEN(int x) { return x == 0 ? 1 : TEN(x-1) * 10; } template inline T ABS(T x) { return max(x, -x); } const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; inline void YES(bool t = 1) { cout << YESNO[t] << "\n"; } inline void Yes(bool t = 1) { cout << YesNo[t] << "\n"; } inline void yes(bool t = 1) { cout << yesno[t] << "\n"; } inline void print() { cout << "\n"; } template inline void print(const vector& v) { for (auto it = begin(v); it != end(v); ++it) { if (it != begin(v)) cout << " "; cout << *it; } print(); } template inline void print(const T& x, const Args& ... args) { cout << x << " "; print(args...); } #ifdef MINATO_LOCAL inline void debug_out() { cerr << endl; } template inline void debug_out(const T& x, const Args& ... args) { cerr << " " << x; debug_out(args...); } #define debug(...) cerr << __LINE__ << " : [" << #__VA_ARGS__ << "] =", debug_out(__VA_ARGS__) #else #define debug(...) (void(0)) #endif struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(7); }; } fast_ios_; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include using namespace atcoder; //using mint = modint998244353; using mint = modint1000000007; //using mint = modint; istream& operator>>(istream& is, modint998244353& M) { long long x; is >> x; M = x; return is; } ostream& operator<<(ostream& os, const modint998244353& M) { return os << M.val(); } istream& operator>>(istream& is, modint1000000007& M) { long long x; is >> x; M = x; return is; } ostream& operator<<(ostream& os, const modint1000000007& M) { return os << M.val(); } template istream& operator>>(istream& is, static_modint& M) { long long x; is >> x; M = x; return is; } template ostream& operator<<(ostream& os, const static_modint& M) { return os << M.val(); } istream& operator>>(istream& is, modint& M) { long long x; is >> x; M = x; return is; } ostream& operator<<(ostream& os, const modint& M) { return os << M.val(); } namespace ArbitraryNTT { constexpr int m0 = 167772161; constexpr int m1 = 469762049; constexpr int m2 = 754974721; constexpr int r01 = 104391568; // mint1(m0).inv() constexpr int r02 = 323560596; // mint2(m0).inv() constexpr int r12 = 399692502; // mint2(m1).inv() // constexpr int m0 = 1045430273; // constexpr int m1 = 1051721729; // constexpr int m2 = 1053818881; // constexpr int r01 = 175287122; // mint1(m0).inv() // constexpr int r02 = 395182206; // mint2(m0).inv() // constexpr int r12 = 526909943; // mint2(m1).inv() constexpr int r02r12 = (long long)(r02) * r12 % m2; constexpr long long w1 = m0; constexpr long long w2 = (long long)(m0) * m1; template vector multiply(const vector& a, const vector& b, int mod) { int n = int(a.size()), m = int(b.size()); vector v0 = convolution(a, b); vector v1 = convolution(a, b); vector v2 = convolution(a, b); vector ret(n + m - 1); const int W1 = w1 % mod; const int W2 = w2 % mod; for (int i = 0; i < n + m - 1; i++) { int n1 = v1[i], n2 = v2[i], x = v0[i]; int y = (long long)(n1 + m1 - x) * r01 % m1; int z = ((long long)(n2 + m2 - x) * r02r12 + (long long)(m2 - y) * r12) % m2; ret[i] = ((long long)(x) + (long long)(y) * W1 + (long long)(z) * W2) % mod; } return ret; } template vector multiply(vector a, vector b) { int n = int(a.size()), m = int(b.size()); if (!n or !m) return {}; if (min(n,m) < 128) { if (n < m) { swap(n, m); swap(a, b); } vector ret(n + m - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ret[i + j] += a[i] * b[j]; } } return ret; } vector a_(n), b_(m); for (int i = 0; i < n; i++) a_[i] = a[i].val(); for (int i = 0; i < m; i++) b_[i] = b[i].val(); vector c = multiply(a_, b_, D::mod()); vector ret(n + m - 1); for (int i = 0; i < n + m - 1; i++) ret[i] = D::raw(c[i]); return ret; } } constexpr int MAX = 2e6; int main() { int p,q; cin >> p >> q; vec a(MAX+1); a[1] = 0; a[2] = 1; for(int i = 3; i <= MAX; i++) a[i] = mint(p)*a[i-1] + a[i-2]; auto c = ArbitraryNTT::multiply(a,a); rep(_,q) { int k; cin >> k; cout << c[k] << ln; } }