#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 5, mod = 1e9 + 7;
inline int inc(int x, int y) { return x += y - mod, x += x >> 31 & mod; }
inline int dec(int x, int y) { return x -= y, x += x >> 31 & mod; }
inline int mul(int x, int y) { return long long(x) * y % mod; }
inline int sed(int x, int y) { return y ? x & 1 ? mod - y : y : 0; }
int qpow(int a, int b) {
  b += b >> 31 & (mod - 1);
  int c = 1;
  for (; b; b >>= 1, a = mul(a, a)) {
    if (b & 1) c = mul(a, c);
  }
  return c;
}
int fac[maxn], fic[maxn], inv[maxn];
void init(int n) {
  fac[0] = 1;
  for (int i = int(1); i <= int(n); i++) fac[i] = mul(fac[i - 1], i);
  fic[n] = qpow(fac[n], -1);
  for (int i = int(n); i >= int(1); i--) fic[i - 1] = mul(fic[i], i);
  for (int i = int(1); i <= int(n); i++) inv[i] = mul(fac[i - 1], fic[i]);
}
inline int binom(int n, int m) {
  return m >= 0 && m <= n ? mul(fac[n], mul(fic[m], fic[n - m])) : 0;
}
int n, q, a[maxn], b[maxn], c[maxn];
int main() {
  scanf("%d %d", &n, &q);
  init(n * 3);
  a[1] = long long(n + 1) * n / 2 * 3 % mod;
  b[1] = dec(a[1], n);
  c[1] = dec(b[1], n);
  for (int i = int(2); i <= int(n * 3); i++) {
    int s = inc(binom(n * 3, i), binom(n * 3, i + 1));
    int d = inc(b[i - 1], mul(2, c[i - 1]));
    c[i] = mul(dec(s, d), (mod + 1) / 3);
    b[i] = inc(c[i - 1], c[i]);
    a[i] = inc(b[i - 1], b[i]);
  }
  for (int k; q--;) {
    scanf("%d", &k);
    printf("%d\n", a[k]);
  }
  return 0;
}
