#include <bits/stdc++.h>
int n, q;
const int mod = 1e9 + 7;
int fac[3333333], inv[3333333];
inline int qpow(int x, int k) {
  int r = 1;
  for (; k; k >>= 1, x = x * 1ll * x % mod)
    if (k & 1) r = r * 1ll * x % mod;
  return r;
}
int ans[3333333], f[3333333], x[3333333];
int C(int n, int r) { return fac[n] * 1ll * inv[r] % mod * inv[n - r] % mod; }
const long long modInf = mod * 3ll;
void divs() {
  for (register int i = n * 3 + 3; i >= 3; i--) {
    int t = f[i];
    ans[i - 3] = f[i];
    f[i - 1] = (f[i - 1] + modInf - t * 3ll) % mod;
    f[i - 2] = (f[i - 2] + modInf - t * 3ll) % mod;
  }
}
void calc() {
  register int i;
  for (i = 1; i <= n * 3 + 3; i++) f[i] = C(n * 3 + 3, i);
  (f[1] += mod - 3) %= mod;
  (f[2] += mod - 3) %= mod;
  (f[3] += mod - 1) %= mod;
  divs();
}
int main() {
  scanf("%d%d", &n, &q);
  register int i;
  const int N = n * 3 + 3;
  for (i = fac[0] = 1; i <= N; i++) fac[i] = fac[i - 1] * 1ll * i % mod;
  for (i = N, inv[N] = qpow(fac[N], mod - 2); i; i--)
    inv[i - 1] = inv[i] * 1ll * i % mod;
  for (i = 1; i <= q; i++) scanf("%d", x + i);
  calc();
  for (i = 1; i <= q; i++) printf("%d\n", ans[x[i]]);
}
