#include #include #include #define llint long long #define mod 1000000007 using namespace std; llint p, Q; llint a[200005], f[200005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> p >> Q; a[2] = 1; for(int i = 3; i < 200005; i++) a[i] = p*a[i-1]%mod + a[i-2], a[i] %= mod; f[1] = 0, f[2] = 0, f[3] = 0, f[4] = 1; for(int i = 5; i < 200005; i++){ f[i] = p*f[i-1]%mod + f[i-2] + a[i-2], f[i] %= mod; } llint x; for(int q = 0; q < Q; q++){ cin >> x; cout << f[x] << endl; } return 0; }