#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
template <typename T>
void print(T&& x) {
  cout << x << "\n";
}
template <typename T, typename... S>
void print(T&& x, S&&... y) {
  cout << x << ' ';
  print(y...);
}
const long long Mod = 1000000007, Mod2 = 998244353;
const long long MOD = Mod;
const long long maxn = 3000005;
template <long long mod>
struct Modint {
  long long val;
  Modint(long long _val = 0) {
    val = _val % mod;
    if (val < 0) val += mod;
  }
  Modint operator+(const Modint& o) const {
    Modint res;
    res.val = val + o.val;
    if (res.val >= mod) res.val -= mod;
    return res;
  }
  Modint operator+(const long long& o) const { return Modint(val + o); }
  Modint operator-() const {
    Modint res;
    res.val = -val;
    if (res.val < 0) res.val += mod;
    return res;
  }
  Modint operator-(const Modint& o) const {
    Modint res;
    res.val = val - o.val;
    if (res.val < 0) res.val += mod;
    return res;
  }
  Modint operator-(const long long& o) const { return Modint(val - o); }
  Modint operator*(const Modint& o) const { return Modint(val * o.val); }
  Modint operator*(const long long& o) const { return Modint(val * (o % mod)); }
  Modint operator+=(const Modint& o) {
    *this = (*this) + o;
    return *this;
  }
  Modint operator-=(const Modint& o) {
    *this = (*this) - o;
    return *this;
  }
  Modint operator*=(const Modint& o) {
    *this = (*this) * o;
    return *this;
  }
  Modint Pow(long long b) const {
    Modint tmp(val), ret(1);
    while (b) {
      if (b & 1) ret *= tmp;
      b >>= 1;
      tmp *= tmp;
    }
    return ret;
  }
  Modint Pow(const Modint& a, long long b) const { return a.Pow(b); }
  inline Modint inv() const { return (*this).Pow(mod - 2); }
  Modint operator/(const Modint& o) const { return *this * o.inv(); }
  Modint operator/(const long long& o) const { return *this * Modint(o).inv(); }
  bool operator==(const Modint& o) const { return val == o.val; }
};
template <long long mod>
ostream& operator<<(ostream& o, Modint<mod> x) {
  return o << x.val;
}
template <long long mod>
Modint<mod> operator+(const long long& x, const Modint<mod>& y) {
  return Modint<mod>(x + y.val);
}
template <long long mod>
Modint<mod> operator-(const long long& x, const Modint<mod>& y) {
  return Modint<mod>(x - y.val);
}
template <long long mod>
Modint<mod> operator*(const long long& x, const Modint<mod>& y) {
  return Modint<mod>(x % mod * y.val);
}
vector<Modint<MOD> > inv, fac, invfac;
void init_comb(long long N) {
  inv.resize(N), fac.resize(N), invfac.resize(N);
  inv[1] = 1, fac[0] = 1, invfac[0] = 1;
  for (long long i = (2); i < ((long long)(N)); i++)
    inv[i] = inv[MOD % i] * (MOD - MOD / i);
  for (long long i = (1); i < ((long long)(N)); i++) fac[i] = fac[i - 1] * i;
  for (long long i = (1); i < ((long long)(N)); i++)
    invfac[i] = invfac[i - 1] * inv[i];
}
inline Modint<MOD> C(long long n, long long m) {
  return m > n || m < 0 ? Modint<MOD>(0) : fac[n] * invfac[m] * invfac[n - m];
}
Modint<MOD> f(long long x, long long y) {
  Modint<MOD> res = 0;
  for (long long i = 3; i <= 3 * x; i += 3) res += C(i, y);
  return res;
}
long long n;
Modint<MOD> val[maxn];
void orzck() {
  init_comb(maxn);
  cin >> n;
  val[0] = n + 1;
  val[1] = n * (n + 1) / 2 * 3;
  Modint<MOD> inv3 = Modint<MOD>(3).inv();
  for (long long i = (2); i < ((long long)(3 * n + 1)); i++)
    val[i] = (C(3 * n + 3, i + 1) - 3 * val[i - 1] - val[i - 2]) * inv3, 826;
  long long t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    print(val[x]);
  }
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cout << fixed << setprecision(15);
  long long t;
  t = 1;
  while (t--) orzck();
  return 0;
}
