#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool mini(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
bool maxi(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int N = 3e6 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7;
const long double pi = 3.14159265359;
int dp[3 * N][3];
int fac[3 * N];
int inv[3 * N];
int n, q;
int binpow(int x, int k) {
  int res = 1;
  for (; k; k >>= 1, x = (long long)x * x % mod)
    if (k & 1) res = (long long)res * x % mod;
  return res;
}
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int C(int k, int n) {
  if (k > n) return 0;
  return (long long)fac[n] * inv[k] % mod * inv[n - k] % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  fac[0] = 1;
  for (int i = 1; i < 3 * N; i++) fac[i] = (long long)fac[i - 1] * i % mod;
  inv[3 * N - 1] = binpow(fac[3 * N - 1], mod - 2);
  for (int i = 3 * N - 2; i >= 0; i--)
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  dp[0][0] = dp[0][1] = dp[0][2] = n + 1;
  int div3 = binpow(3, mod - 2);
  for (int i = 1; i <= 3 * n; i++) {
    dp[i][0] = C(i + 1, 3 * n + 3);
    add(dp[i][0], mod - 2 * dp[i - 1][0] % mod);
    add(dp[i][0], mod - dp[i - 1][1] % mod);
    dp[i][0] = (long long)dp[i][0] * div3 % mod;
    dp[i][1] = (dp[i - 1][0] + dp[i][0]) % mod;
    dp[i][2] = (dp[i - 1][1] + dp[i][1]) % mod;
  }
  while (q--) {
    int x;
    cin >> x;
    cout << dp[x][0] << "\n";
  }
  return 0;
}
