#include <bits/stdc++.h>
using namespace std;
auto rng = bind(uniform_int_distribution<int>(1, 1000), mt19937(time(0)));
template <class T>
bool umin(T &a, const T &b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T>
bool umax(T &a, const T &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug &operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug &operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
const long long inf = 1e18;
const int N = 3e6 + 4;
const int M = 1e9 + 7;
int fact[N], obr[N];
void add(int &a, int b) {
  a += b;
  if (a >= M)
    a -= M;
  else if (a < 0)
    a += M;
}
int sm(int a, int b) {
  add(a, b);
  return a;
}
int mult(int a, int b) { return 1ll * a * b % M; }
int C(int n, int k) {
  if (k > n) return 0;
  return 1ll * fact[n] * obr[k] % M * obr[n - k] % M;
}
int binpow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = mult(ans, a);
    b >>= 1;
    a = mult(a, a);
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = mult(fact[i - 1], i);
  obr[N - 1] = binpow(fact[N - 1], M - 2);
  for (int i = N - 2; i >= 0; i--) obr[i] = mult(obr[i + 1], i + 1);
  int n, q;
  cin >> n >> q;
  vector<vector<int>> dp(3 * n + 1, vector<int>(3, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      add(dp[0][j], C(3 * i + j, 0));
    }
  }
  int d3 = binpow(3, M - 2);
  for (int x = 1; x < (int)dp.size(); x++) {
    dp[x][0] = sm(C(3 * n, x + 1), -mult(2, dp[x - 1][0]));
    add(dp[x][0], -dp[x - 1][1]);
    dp[x][0] = mult(dp[x][0], d3);
    dp[x][1] = sm(dp[x][0], dp[x - 1][0]);
    dp[x][2] = sm(dp[x][1], dp[x - 1][1]);
  }
  while (q--) {
    int x;
    cin >> x;
    cout << sm(C(3 * n, x), dp[x][0]) << '\n';
  }
  return 0;
}
