#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int MAX_SIZE = 1e6 + 5;
const long long int MAXN = 3e6 + 5;
const long long int INF = 2e18;
vector<long long int> fact;
vector<long long int> modin;
long long int factorial(long long int n) {
  return (n == 1 || n == 0) ? 1 : (n * factorial(n - 1)) % mod;
}
long long int power(long long int a, long long int p) {
  if (p == 0) {
    return 1;
  } else if (p % 2 == 0) {
    long long int t = power(a, p / 2);
    return (t * t) % mod;
  } else {
    return (a * power(a, p - 1)) % mod;
  }
}
long long int modInverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
void fill() {
  fact[0] = 1;
  long long int l1 = fact.size();
  for (long long int i = 1; i < l1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  modin[l1 - 1] = power(fact[l1 - 1], mod - 2);
  for (long long int i = l1 - 2; i >= 0; i--) {
    modin[i] = (modin[i + 1] * (i + 1)) % mod;
  }
}
long long int nCr(long long int n, long long int r) {
  if (r > n) {
    return 0;
  } else {
    return (((fact[n] * modin[n - r]) % mod) * modin[r]) % mod;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, q;
  cin >> n >> q;
  long long int modin3 = modInverse(3, mod);
  fact = vector<long long int>(3 * n + 5);
  modin = vector<long long int>(3 * n + 5);
  fill();
  vector<vector<long long int>> dp(3 * n + 1, vector<long long int>(3));
  dp[0][0] = n;
  dp[0][1] = n;
  dp[0][2] = n;
  for (long long int i = 1; i < 3 * n + 1; i++) {
    dp[i][0] =
        (((nCr(3 * n, i + 1) - dp[i - 1][1] - 2 * dp[i - 1][0]) * modin3) %
             mod +
         mod) %
        mod;
    dp[i][1] = dp[i][0] + dp[i - 1][0];
    dp[i][1] %= mod;
    dp[i][2] = dp[i][1] + dp[i - 1][1];
    dp[i][2] %= mod;
  }
  for (long long int i = 0; i < q; i++) {
    long long int x;
    cin >> x;
    cout << (dp[x][0] + nCr(3 * n, x)) % mod << '\n';
  }
  return 0;
}
