#include <bits/stdc++.h>
using namespace std;
struct Combo {
  long long* fact;
  long long* inv;
  void build(long long n) {
    fact = new long long[n];
    inv = new long long[n];
    fact[0] = 1;
    inv[0] = 1;
    for (int i = 1; i < n; i++) {
      fact[i] = (fact[i - 1] * (long long)i) % 1000000007ll;
      inv[i] = binexp(fact[i], 1000000007ll - 2);
    }
  }
  long long binexp(long long a, long long b) {
    if (b == 0) return 1ll;
    if (b == 1) return a % 1000000007ll;
    if (b % 2) return (a * binexp(a, b - 1)) % 1000000007ll;
    return binexp((a * a) % 1000000007ll, b / 2);
  }
  long long choose(long long a, long long b) {
    if (a < b) return 0;
    long long res = (fact[a] * inv[b]) % 1000000007ll;
    res *= inv[a - b];
    res %= 1000000007ll;
    return res;
  }
} helper;
int n, q;
long long dp[1000010 * 3][3];
int main() {
  scanf(" %d%d", &n, &q);
  helper.build(3 * n + 2);
  for (int i = 0; i < 3; i++) dp[0][i] = n;
  long long inv3 = helper.binexp(3, 1000000007ll - 2);
  for (int i = 1; i <= 3 * n; i++) {
    dp[i][1] = helper.choose(3 * n + 1, i + 1);
    long long B = dp[i - 1][1];
    long long C = dp[i - 1][2];
    dp[i][1] -= C;
    dp[i][1] -= 2 * B;
    dp[i][1] += 69 * 1000000007ll;
    dp[i][1] %= 1000000007ll;
    dp[i][1] *= inv3;
    dp[i][1] %= 1000000007ll;
    dp[i][2] = (B + dp[i][1]) % 1000000007ll;
    dp[i][0] = (C + dp[i][2]) % 1000000007ll;
  }
  while (q--) {
    int x;
    scanf("%d", &x);
    printf("%lld\n", dp[x][0]);
  }
}
