#include #include #include #include #include #include #include #include #include #include #include #define MOD (1000000007l) #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; void solve() { ll N, P; N = 2000010; cin >> P; vector A(N); A[0] = 0; A[1] = 1; for (ll i = 2; i < N; i++) { ll tmp = P * A[i-1] + A[i-2]; tmp %= MOD; A[i] = tmp; } vector B(N); B[0] = 0; B[1] = 0; for (ll i = 2; i < N; i++) { B[i] = P * B[i-1] + B[i-2] + A[i-2]; B[i] %= MOD; } ll Q; cin >> Q; rep (i, Q) { ll tmp; cin >> tmp; cout << B[tmp-1] << endl; } } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout.precision(12); cout << fixed; solve(); return 0; }