#include <bits/stdc++.h>
using namespace std;
const long long modd = (1000LL * 1000LL * 1000LL + 7LL);
template <class T>
T fastpower(T x, long long pw, T id = 1) {
  T w = x, res = id;
  while (pw > 0) {
    if (pw & 1) {
      res = (res * w);
    }
    pw >>= 1;
    w = (w * w);
  }
  return res;
}
class Mint {
  friend ostream& operator<<(ostream& o, const Mint& b);

 public:
  Mint() : val(0) {}
  Mint(long long x) {
    if (x < 0) {
      x += (1 + abs(x) / modd) * modd;
    }
    val = x % modd;
  }
  Mint operator+(const Mint& b) const { return Mint((val + b.val) % modd); }
  Mint operator-(const Mint& b) const {
    return Mint((val + modd - b.val) % modd);
  }
  Mint operator*(const Mint& b) const { return Mint((val * b.val) % modd); }
  Mint operator/(const Mint& b) const {
    return Mint(*this * fastpower<Mint>(b, modd - 2));
  }
  Mint operator-() const { return Mint((val * (modd - 1)) % modd); }
  Mint& operator+=(const Mint& b) {
    val += b.val;
    val %= modd;
    return *this;
  }
  Mint& operator-=(const Mint& b) {
    val += modd - b.val;
    val %= modd;
    return *this;
  }
  Mint& operator*=(const Mint& b) {
    val *= b.val;
    val %= modd;
    return *this;
  }
  Mint& operator/=(const Mint& b) {
    val = (Mint(val) / b).val;
    return *this;
  }
  Mint& operator++() {
    ++val;
    return *this;
  }
  Mint operator++(int) {
    Mint old = *this;
    operator++();
    return old;
  }
  Mint& operator--() {
    --val;
    return *this;
  }
  Mint operator--(int) {
    Mint old = *this;
    operator--();
    return old;
  }
  bool operator==(const Mint& b) const { return val == b.val; }

 private:
  long long val;
};
ostream& operator<<(ostream& o, const Mint& b) { return (o << b.val); }
class Factorial {
 public:
  vector<Mint> bin;
  Factorial(int n) : bin(n + 1, 0) {
    bin[0] = 1;
    for (int i = (1); i < (1) + (n); ++i) {
      bin[i] = Mint(i) * bin[i - 1];
    }
  }
  Mint val(int i) { return bin[i]; }
};
class BinomialWithFactorial {
 public:
  Factorial fact;
  vector<Mint> inverse_fact;
  BinomialWithFactorial(int n) : fact(n) { FillInverse(); }
  BinomialWithFactorial(Factorial& f) : fact(f) { FillInverse(); }
  void FillInverse() {
    for (int i = (0); i < (0) + (fact.bin.size()); ++i) {
      inverse_fact.push_back(Mint(1) / fact.val(i));
    }
  }
  Mint val(int i, int j) {
    if (i < 0) {
      return 0;
    }
    if ((j < 0) || (j > i)) {
      return 0;
    }
    Mint temp = (fact.val(i) * inverse_fact[j]);
    return (temp * inverse_fact[i - j]);
  }
};
int main(int argc, char* argv[]) {
  mt19937 rang(chrono::steady_clock::now().time_since_epoch().count());
  uniform_int_distribution<int> rand_gen(0, modd);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(12);
  int test_cases = 1;
  for (int t = (1); t < (1) + (test_cases); ++t) {
    int n;
    cin >> n;
    int q;
    cin >> q;
    BinomialWithFactorial bin(3 * n + 5);
    vector<Mint> a(3 * n + 4);
    for (int i = (0); i < (0) + (a.size()); ++i) {
      a[i] += bin.val(3 * n + 3, i + 1);
      a[i] -= bin.val(3, i + 1);
      if (i - 1 >= 0) a[i] -= Mint(3) * a[i - 1];
      if (i - 2 >= 0) a[i] -= a[i - 2];
      a[i] /= Mint(3);
    }
    for (int i = (0); i < (0) + (q); ++i) {
      int x;
      cin >> x;
      cout << a[x] << "\n";
    }
  }
  return 0;
}
