#include <bits/stdc++.h>
using namespace std;
const int kMod = 1e9 + 7;
int Add(int x, int y) {
  x += y;
  if (x >= kMod) x -= kMod;
  if (x < 0) x += kMod;
  return x;
}
int fpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res = 1LL * res * a % kMod;
    n >>= 1, a = 1LL * a * a % kMod;
  }
  return res;
}
int Inv(int x) { return fpow(x, kMod - 2); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector<vector<int>> dp(3, vector<int>(3 * n + 1));
  vector<int> fac(3 * n + 5), inv(3 * n + 5);
  fac[0] = 1;
  for (int i = 1; i <= 3 * n + 4; i++) fac[i] = 1LL * i * fac[i - 1] % kMod;
  inv[3 * n + 4] = Inv(fac[3 * n + 4]);
  for (int i = 3 * n + 3; i >= 0; i--)
    inv[i] = 1LL * (i + 1) * inv[i + 1] % kMod;
  auto C = [&](int n, int m) -> int {
    if (n < m) return 0;
    return int(1LL * fac[n] * inv[n - m] % kMod * inv[m] % kMod);
  };
  dp[0][0] = dp[1][0] = dp[2][0] = n;
  for (int i = 1; i <= 3 * n; i++) {
    dp[1][i] = 1LL *
               Add(Add(C(3 * n + 1, i + 1), -dp[2][i - 1]),
                   -2LL * dp[1][i - 1] % kMod) *
               Inv(3) % kMod;
    dp[2][i] = Add(dp[1][i], dp[1][i - 1]);
    dp[0][i] = Add(dp[2][i], dp[2][i - 1]);
  }
  while (q--) {
    int x;
    cin >> x;
    cout << dp[0][x] << '\n';
  }
  return 0;
}
