#include <bits/stdc++.h>
using namespace std;
int n, p;
int fac[505], F[505], G[505][505], ans[505];
int main() {
  int T;
  scanf("%d%d", &T, &p);
  n = 500;
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % p;
  F[1] = 1;
  for (int i = 2; i <= n; ++i) {
    F[i] = fac[i];
    for (int j = 1; j < i; ++j) F[i] = (F[i] - 1LL * F[j] * fac[i - j]) % p;
  }
  G[0][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= i; ++j) {
      G[i][j] = 0;
      for (int k = 1; k <= i; ++k)
        G[i][j] = (G[i][j] + 1LL * G[i - k][j - 1] * fac[k]) % p;
    }
  ans[1] = 1;
  for (int i = 2; i <= n; ++i) {
    ans[i] = fac[i];
    for (int j = 1; j < i; ++j) ans[i] = (ans[i] - 2LL * F[j] * fac[i - j]) % p;
    for (int j = 3; j < i; ++j) ans[i] = (ans[i] - 1LL * G[i][j] * ans[j]) % p;
  }
  ans[2] = 2;
  for (; T; --T) {
    scanf("%d", &n);
    printf("%d\n", (ans[n] + p) % p);
  }
}
