#include #define REP(i, x, y) for (ll i = x; i <= y; i++) #define BIT(t) (1ll << t) #define PER(i, y, x) for (ll i = y; i >= x; i--) #define vll vector #define vvll vector> #define pll pair #define SIZE(v) ll(v.size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); using namespace std; typedef long long ll; // ios::sync_with_stdio(false); // cin.tie(nullptr); ll const MOD = 1000000007; ll mod_p(ll x, ll y) { x %= MOD; y %= MOD; return (x + y + MOD) % MOD; } ll mod_m(ll x, ll y) { x %= MOD; y %= MOD; return x * y%MOD; } ll mod_pow(ll x, ll t) { x %= MOD; if (t == 0) { return 1; } else { ll v = mod_pow(x, t / 2); if (t % 2 == 0) { return v * v % MOD; } else { return v * v%MOD * x %MOD; } } } ll mod_inv(ll x) { return mod_pow(x, MOD - 2); } int main(){ ll p; cin >> p; ll const MAX = 2e6; vll a(2e6 + 1); vll b(2e6 + 1, 0); a[1] = 0; a[2] = 1; REP(i,3,MAX){ a[i] = mod_p(a[i-2], mod_m(a[i-1], p)); } REP(i,3,MAX){ b[i] = mod_p(a[i-2], mod_p(b[i-2], mod_m(b[i-1], p))); } vll ans; ll q; cin >> q; REP(i,1,q){ ll t; cin >> t; ans.push_back(b[t]); } REP(i,0,q-1){ cout << ans[i] << endl; } }