#include <bits/stdc++.h>
using namespace std;
const int N = 3000000, mod = 1000000007;
int add(int a, int b, int p = mod) { return a + b >= p ? a + b - p : a + b; }
int sub(int a, int b, int p = mod) { return a - b < 0 ? a - b + p : a - b; }
int mul(int a, int b, int p = mod) { return 1LL * a * b % p; }
void sadd(int &a, int b, int p = mod) { a = add(a, b, p); }
void ssub(int &a, int b, int p = mod) { a = sub(a, b, p); }
void smul(int &a, int b, int p = mod) { a = mul(a, b, p); }
int n, cq;
void into() { scanf("%d%d", &n, &cq); }
int inv[N + 9], ans[N + 9];
void Get_ans() {
  int m = 3 * n + 3;
  for (int i = 1, c = 1; i <= m; ++i) {
    inv[i] = i == 1 ? 1 : mul(mod - mod / i, inv[mod % i]);
    c = mul(c, mul(m - i + 1, inv[i]));
    ans[i - 1] = c;
  }
  for (int i = m - 1; i >= 2; --i) {
    int t = mul(ans[i], 3);
    ssub(ans[i - 1], t);
    ssub(ans[i - 2], t);
  }
}
void work() { Get_ans(); }
void outo() {
  for (; cq--;) {
    int x;
    scanf("%d", &x);
    printf("%d\n", ans[x + 2]);
  }
}
int main() {
  int T = 1;
  for (; T--;) {
    into();
    work();
    outo();
  }
  return 0;
}
