#include <bits/stdc++.h>
using namespace std;
int t;
long long p, fac[405], dp[405], two[405], mor[405][405], ans[405];
int ta;
void add(long long& a, long long b) {
  a += b;
  if (a >= p) a -= p;
}
int main() {
  scanf("%d%lld", &t, &p);
  fac[0] = 1;
  mor[0][0] = 1;
  for (int i = 1; i <= 400; i++) {
    fac[i] = fac[i - 1] * i % p;
    dp[i] = fac[i];
    for (int j = 1; j < i; j++) add(dp[i], p - dp[j] * fac[i - j] % p);
    for (int j = 1; j < i; j++) two[i] = (two[i] + dp[j] * fac[i - j] * 2) % p;
    for (int j = 0; j < i; j++)
      for (int k = 0; k <= j; k++)
        mor[i][k + 1] = (mor[i][k + 1] + mor[j][k] * fac[i - j]) % p;
    ans[i] = fac[i];
    for (int j = 3; j < i; j++) add(ans[i], p - ans[j] * mor[i][j] % p);
    add(ans[i], p - two[i]);
  }
  ans[2] = 2;
  while (t--) {
    scanf("%d", &ta);
    printf("%lld\n", ans[ta]);
  }
  return 0;
}
