#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 405;
int n = maxn, p, m;
long long f[maxn + 5];
long long ans[maxn + 5];
long long xx[maxn + 5];
long long B[maxn + 5][maxn + 5];
void getF() {
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = f[i - 1] * 1ll * i % p;
}
void solve() {
  getF();
  for (int i = 1; i <= n; i++) {
    xx[i] = f[i];
    for (int k = 1; k <= i - 1; k++) {
      xx[i] = (xx[i] - xx[i - k] * f[k] % p + p) % p;
    }
  }
  B[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int t = 1; t <= i; t++) {
        B[i][j] = (B[i][j] + B[i - t][j - 1] * f[t] % p) % p;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = f[i];
    if (i > 2)
      for (int k = 1; k <= i - 1; k++) {
        ans[i] = (ans[i] - 2 * xx[i - k] % p * f[k] % p + p) % p;
      }
    for (int k = 3; k <= i - 1; k++) {
      ans[i] = (ans[i] - B[i][k] * ans[k] % p + p) % p;
    }
  }
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%d", &x);
    printf("%lld\n", ans[x]);
  }
}
int main() {
  scanf("%d%d", &m, &p);
  solve();
  return 0;
}
