#include <bits/stdc++.h>
using namespace std;
int T, MOD;
long long qp(long long a, long long b) {
  long long x = 1;
  a %= MOD;
  while (b) {
    if (b & 1) x = x * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return x;
}
long long fac[666666], rfac[666666], ans[666666], c[666666];
void operator*=(vector<int>& a, vector<int>& b) {
  for (int i = 0; i < 403; ++i) c[i] = 0;
  for (int i = 0; i < 403; ++i) {
    for (int j = 0; j <= i; ++j) {
      c[i] += a[j] * (long long)b[i - j];
      if (!(j & 7)) c[i] %= MOD;
    }
    c[i] %= MOD;
  }
  for (int i = 0; i < 403; ++i) a[i] = c[i];
}
int main() {
  cin >> T >> MOD;
  fac[0] = 1;
  for (int i = 1; i < 666666; ++i) fac[i] = fac[i - 1] * i % MOD;
  rfac[666666 - 1] = qp(fac[666666 - 1], MOD - 2);
  for (int i = 666666 - 1; i >= 1; --i) rfac[i - 1] = rfac[i] * i % MOD;
  vector<int> v, x, a;
  a.resize(403);
  a[0] = 1;
  x.resize(403);
  for (int i = 0; i < 403; ++i) v.push_back(fac[i + 1]);
  for (int i = 0; i < 403; ++i) {
    long long t = (i == 0);
    for (int j = 0; j < i; ++j) t = (t - v[i - j] * (long long)x[j]) % MOD;
    x[i] = t;
  }
  for (int i = 1; i <= 400; ++i) {
    a *= x;
    ans[i] = -a[i - 1] * (long long)rfac[i] % MOD * fac[i - 1] % MOD;
    if ((i + 1) & 1)
      ans[i] -= 2;
    else
      ans[i] += 2;
    if (i == 2) ans[i] = 2;
  }
  while (T--) {
    int n;
    cin >> n;
    n = ans[n];
    n = (n % MOD + MOD) % MOD;
    cout << n << "\n";
  }
}
