#include <bits/stdc++.h>
using namespace std;
template <typename M, typename N>
istream &operator>>(istream &is, pair<M, N> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename M>
istream &operator>>(istream &is, vector<M> &v) {
  for (auto &it : v) is >> it;
  return is;
}
template <typename M>
istream &operator>>(istream &is, vector<vector<M>> &v) {
  for (auto &it : v) is >> it;
  return is;
}
template <typename M, typename N>
ostream &operator<<(ostream &os, const pair<M, N> &p) {
  os << p.first << ' ' << p.second << '\n';
  return os;
}
template <typename M>
ostream &operator<<(ostream &os, const vector<M> &v) {
  for (auto it : v) os << it << ' ';
  cout << '\n';
  return os;
}
template <typename M>
ostream &operator<<(ostream &os, const vector<vector<M>> &v) {
  for (auto it : v) os << it;
  return os;
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int a, int b) { return rng() % (b - a + 1) + a; }
const long double eps = 1e-7;
const long double pi = acos(-1);
const long long inf = (long long)1e9 + 10;
const int mod = 1000000007;
int n, m, k;
const int N = 1e6 + 10;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
vector<long long int> fact, fact_inverse;
template <typename type>
void tabulate(type n) {
  fact.resize(n + 1);
  fact_inverse.resize(n + 1);
  fact[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  fact_inverse[n] = binpow(fact[n], mod - 2, mod);
  for (int i = n - 1; i >= 0; i--) {
    fact_inverse[i] = fact_inverse[i + 1] * (i + 1) % mod;
  }
}
template <typename type>
long long int nCk(type n, type k) {
  return n < k ? 0
               : fact[n] * fact_inverse[n - k] % mod * fact_inverse[k] % mod;
}
template <typename type>
long long int nPk(type n, type k) {
  return n < k ? 0 : fact[n] * fact_inverse[n - k] % mod;
}
struct mint {
  long long x;
  mint(){};
  mint(long long xx) : x(xx) {}
  mint operator+(const mint &b) {
    return x + b.x >= mod ? x + b.x - mod : x + b.x;
  }
  mint operator-(const mint &b) { return x >= b.x ? x - b.x : x - b.x + mod; }
  mint operator*(const mint &b) { return x * b.x % mod; }
  mint operator/(const mint &b) { return *this * inverse(b); }
  mint operator+=(const mint &b) { return *this = *this + b; }
  mint operator-=(const mint &b) { return *this = *this - b; }
  mint operator*=(const mint &b) { return *this = *this * b; }
  mint operator/=(const mint &b) { return *this = *this / b; }
  bool operator==(const mint &b) { return x == b.x; }
  bool operator!=(const mint &b) { return x != b.x; }
  bool operator<(const mint &b) { return x < b.x; }
  bool operator>(const mint &b) { return x > b.x; }
  mint operator++() { return *this = *this + 1; }
  mint operator--() { return *this = *this - 1; }
  mint operator-() { return x ? mod - x : 0; }
  mint operator^(long long e) {
    mint r = 1;
    mint xx = x;
    while (e) {
      if (e & 1) r *= xx;
      xx *= xx;
      e >>= 1;
    }
    return r;
  }
  mint inverse(mint a) { return a ^ (mod - 2); }
  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }
  friend istream &operator>>(istream &in, mint &m) {
    in >> m.x;
    return in;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  tabulate(3 * n + 10);
  vector<mint> v(3 * n + 4);
  for (int i = 0; i <= 3 * n + 3; i++) {
    v[i] = nCk(3 * n + 3, i);
  }
  vector<mint> ans(3 * n + 1), temp(4);
  temp[0] = 0;
  temp[1] = 3;
  temp[2] = 3;
  temp[3] = 1;
  mint t, tt = (mint)1 / temp[3];
  for (int i = 3 * n + 3; i >= 4; i--) {
    t = v[i] * tt;
    ans[i - 3] = t;
    for (int j = i - 1; j >= i - 3; j--) {
      v[j] -= t * temp[3 - i + j];
    }
  }
  for (int i = 0, u; i < q; i++) {
    cin >> u;
    cout << ans[u] << '\n';
  }
  return 0;
}
