#include <bits/stdc++.h>
using namespace std;
int read() {
  char c = getchar();
  int d = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar())
    ;
  return d * f;
}
const int mod = 1e9 + 7;
const int N = 3000010;
int n, q, ft[N + 1], Ft[N + 1], ans[N + 1];
int mi(int a, int b) {
  int s = 1;
  for (; b; b >>= 1, a = (long long)a * a % mod)
    if (b & 1) s = (long long)s * a % mod;
  return s;
}
int main() {
  n = read(), q = read();
  int maxn = n * 3 + 1;
  ft[0] = 1;
  for (int i = 1; i <= maxn; ++i) ft[i] = 1LL * ft[i - 1] * i % mod;
  Ft[maxn] = mi(ft[maxn], mod - 2);
  for (int i = maxn; i >= 1; --i) Ft[i - 1] = 1LL * Ft[i] * i % mod;
  long long y0 = (3LL * (n + 1) * n / 2) % mod, y1 = (y0 + mod - n * 2) % mod,
            y2 = (y0 + mod - n) % mod, ni3 = mi(3, mod - 2);
  ans[1] = y0;
  for (int i = 2; i <= n * 3; ++i) {
    long long sum = 1LL * ft[maxn] * Ft[i + 1] % mod * Ft[maxn - 1 - i] % mod;
    long long x1 = (sum - y1 - y1 - y2) * ni3 % mod;
    if (x1 < 0) x1 += mod;
    long long x2 = (x1 + y1);
    if (x2 >= mod) x2 -= mod;
    long long x0 = (x2 + y2);
    if (x0 >= mod) x0 -= mod;
    y0 = x0, y1 = x1, y2 = x2;
    ans[i] = x0;
  }
  for (int i = 1; i <= q; ++i) {
    int x = read();
    printf("%d\n", ans[x]);
  }
}
