#include <bits/stdc++.h>
using namespace std;
long long T, a, d[200001], an, b, mod = 1000000007, fac[4000001], inv[4000001],
                                  dp[4000001];
long long pow_(long long qq, long long ww) {
  long long ee = 1;
  while (ww) {
    if (ww & 1) {
      ee *= qq;
      ee %= mod;
    }
    qq *= qq;
    qq %= mod;
    ww >>= 1;
  }
  return ee % mod;
}
long long C(long long qq, long long ww) {
  if (qq < ww) return 0;
  return fac[qq] * inv[ww] % mod * inv[qq - ww] % mod;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i <= 4000000; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  inv[4000000] = pow_(fac[4000000], mod - 2);
  for (int i = 3999999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % mod;
  }
  scanf("%lld%lld", &a, &b);
  for (int j = 1; j <= a; j++) {
    dp[1] += C(j * 3, 1);
    dp[1] %= mod;
    dp[2] += C(j * 3, 2);
    dp[2] %= mod;
  }
  long long tt = pow_(3, mod - 2);
  for (int i = 3; i <= a * 3; i++) {
    dp[i] = (C(3 * a + 3, i + 1) - dp[i - 1] * 3 - dp[i - 2]) % mod * tt % mod;
    dp[i] %= mod;
    dp[i] += mod;
    dp[i] %= mod;
  }
  for (int i = 1; i <= b; i++) {
    scanf("%lld", &d[i]);
    printf("%lld\n", dp[d[i]]);
  }
  return 0;
}
