#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  bool f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int N = 3e6 + 10;
const int mod = 1e9 + 7;
const int inv3 = (mod + 1) / 3;
int fac[N], ifac[N], n, q, f[N][3];
long long qp(long long x, int t) {
  long long res = 1;
  for (; t; t >>= 1, x = x * x % mod)
    if (t & 1) res = res * x % mod;
  return res;
}
int upd(int x) { return x + (x >> 31 & mod); }
long long C(int x, int y) {
  return x < y || x < 0 || y < 0
             ? 0
             : (long long)fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int main() {
  n = read(), q = read();
  for (int i = (fac[0] = 1); i <= 3 * n + 1; i++)
    fac[i] = (long long)fac[i - 1] * i % mod;
  ifac[3 * n + 1] = qp(fac[3 * n + 1], mod - 2);
  for (int i = 3 * n; i >= 0; i--)
    ifac[i] = (long long)ifac[i + 1] * (i + 1) % mod;
  f[0][0] = f[0][1] = f[0][2] = n;
  for (int i = 1; i <= 3 * n; i++) {
    f[i][0] = upd(C(3 * n, i + 1) - 2ll * f[i - 1][0] % mod);
    f[i][0] = upd(f[i][0] - f[i - 1][1] % mod);
    f[i][0] = (long long)f[i][0] * inv3 % mod;
    f[i][1] = upd(f[i - 1][0] + f[i][0] - mod);
    f[i][2] = upd(f[i - 1][1] + f[i][1] - mod);
  }
  while (q--) {
    int x = read();
    if (x == 3 * n) {
      printf("%d\n", 1);
      continue;
    }
    long long ans = f[x][0] + C(3 * n, x);
    ans %= mod;
    printf("%lld\n", ans);
  }
}
