#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3e6 + 50;
long long fact[maxn], inv[maxn];
long long qpow(long long a, long long b, int mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = 1ll * ans * a % mod;
    b >>= 1;
    a = 1ll * a * a % mod;
  }
  return ans;
}
void init() {
  fact[0] = 1;
  for (int i = 1; i < maxn; i++) fact[i] = 1ll * fact[i - 1] * i % mod;
  inv[maxn - 1] = qpow(fact[maxn - 1], mod - 2, mod);
  for (int i = maxn - 2; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
long long C(long long n, long long m, int mod) {
  if (n < 0 || m < 0 || m > n) return 0;
  if (m == 0 || m == n) return 1;
  return 1ll * fact[n] * inv[m] % mod * inv[n - m] % mod;
}
long long sum[maxn];
void solve() {
  init();
  int n, q;
  cin >> n >> q;
  for (long long i = 0; i <= 3 * n + 3; i++) {
    sum[i] = C(3ll * n + 3, i, mod) % mod;
  }
  for (int i = 3 * n + 3; i >= 3; i--) {
    sum[i - 1] -= sum[i] * 3;
    sum[i - 1] = (sum[i - 1] + 1ll * 3 * mod) % mod;
    sum[i - 2] -= sum[i] * 3;
    sum[i - 2] = (sum[i - 2] + 1ll * 3 * mod) % mod;
  }
  while (q--) {
    int x;
    cin >> x;
    cout << sum[x + 3] << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
}
