#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, N = 3e6 + 500;
namespace GTI {
char gc(void) {
  const int S = 1 << 17;
  static char buf[S], *s = buf, *t = buf;
  if (s == t) t = buf + fread(s = buf, 1, S, stdin);
  if (s == t) return EOF;
  return *s++;
}
long long gti(void) {
  long long a = 0, b = 1, c = gc();
  for (; !isdigit(c); c = gc()) b ^= (c == '-');
  for (; isdigit(c); c = gc()) a = a * 10 + c - '0';
  return b ? a : -a;
}
}  // namespace GTI
using GTI::gti;
int fpw(int a, int b) {
  a %= M, b %= M - 1;
  if (b < 0) b += M - 1;
  int c = 1;
  for (; b; b >>= 1, a = 1ll * a * a % M)
    if (b & 1) c = 1ll * c * a % M;
  return c;
}
int a[N], b[N], c[N], fct[N], inv[N];
void init(int n) {
  fct[0] = 1;
  for (int i = 1; i <= n; i++) fct[i] = 1ll * fct[i - 1] * i % M;
  inv[n] = fpw(fct[n], -1);
  for (int i = n - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1ll) % M;
}
int C(int n, int m) {
  if (n < 0 || m < 0 || n - m < 0) return 0;
  return 1ll * fct[n] * inv[m] % M * inv[n - m] % M;
}
int main(void) {
  int n = gti(), q = gti();
  init(n * 3 + 2);
  a[3 * n] = 1, b[3 * n] = 0, c[3 * n] = 0;
  for (int i = n * 3 - 1; i >= 0; i--) {
    a[i] = (1ll * b[i + 1] - a[i + 1] + C(3 * n + 1, i + 1)) % M;
    b[i] = (c[i + 1] - b[i + 1]) % M;
    c[i] = (1ll * a[i + 1] - c[i + 1] - C(3, i + 1)) % M;
  }
  for (int i = 1; i <= q; i++) printf("%d\n", (a[gti()] % M + M) % M);
  return 0;
}
