#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 10, mod = 1e9 + 7;
template <class T>
inline bool ckmin(T &x, const T &y) {
  return x > y ? x = y, 1 : 0;
}
template <class T>
inline bool ckmax(T &x, const T &y) {
  return x < y ? x = y, 1 : 0;
}
struct modint {
  int val;
  inline modint(int val_ = 0) : val(val_) {}
  inline modint &operator=(int val_) { return val = val_, *this; }
  inline modint &operator+=(const modint &k) {
    return val = val + k.val >= mod ? val + k.val - mod : val + k.val, *this;
  }
  inline modint &operator-=(const modint &k) {
    return val = val - k.val < 0 ? val - k.val + mod : val - k.val, *this;
  }
  inline modint &operator*=(const modint &k) {
    return val = 1ll * val * k.val % mod, *this;
  }
  inline modint &operator^=(int k) {
    modint ret = 1, tmp = *this;
    for (; k; k >>= 1, tmp *= tmp)
      if (k & 1) ret *= tmp;
    return val = ret.val, *this;
  }
  inline modint &operator/=(modint k) { return *this *= (k ^= mod - 2); }
  inline modint &operator+=(int k) {
    return val = val + k >= mod ? val + k - mod : val + k, *this;
  }
  inline modint &operator-=(int k) {
    return val = val < k ? val - k + mod : val - k, *this;
  }
  inline modint &operator*=(int k) { return val = 1ll * val * k % mod, *this; }
  inline modint &operator/=(int k) { return *this *= ((modint(k)) ^= mod - 2); }
  template <class T>
  friend modint operator+(modint a, T b) {
    return a += b;
  }
  template <class T>
  friend modint operator-(modint a, T b) {
    return a -= b;
  }
  template <class T>
  friend modint operator*(modint a, T b) {
    return a *= b;
  }
  template <class T>
  friend modint operator/(modint a, T b) {
    return a /= b;
  }
  friend modint operator^(modint a, int b) { return a ^= b; }
  friend bool operator==(modint a, int b) { return a.val == b; }
  friend bool operator!=(modint a, int b) { return a.val != b; }
  inline bool operator!() { return !val; }
  inline modint operator-() { return val ? mod - val : 0; }
  inline modint &operator++(int) { return *this += 1; }
};
using mi = modint;
mi fac[maxn], ifac[maxn];
inline void init(int sz) {
  fac[0] = 1;
  for (register int i = 1; i <= sz; ++i) fac[i] = fac[i - 1] * i;
  ifac[sz] = 1 / fac[sz];
  for (register int i = sz; i; --i) ifac[i - 1] = ifac[i] * i;
}
inline mi C(int x, int y) {
  if (x < y) return 0;
  return fac[x] * ifac[y] * ifac[x - y];
}
mi f[maxn][3], inv3 = 1 / mi(3);
int m, n;
int main() {
  scanf("%d%d", &n, &m);
  init(3 * n + 3);
  f[0][0] = f[0][1] = f[0][2] = n + 1;
  for (register int i = 1; i <= 3 * n; ++i) {
    f[i][0] = (C(3 * n + 3, i + 1) - 2 * f[i - 1][0] - f[i - 1][1]) * inv3;
    f[i][1] = f[i - 1][0] + f[i][0];
    f[i][2] = f[i - 1][1] + f[i][1];
  }
  while (m--) {
    register int x = 0;
    scanf("%d", &x);
    printf("%d\n", f[x][0]);
  }
  return 0;
}
