#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 404;
int T, mo, n = 400, f[N], g[N][N], fac[N];
int main() {
  read(T);
  read(mo);
  fac[0] = 1;
  for (register int i = (1); i <= (n); i++) fac[i] = 1LL * fac[i - 1] * i % mo;
  g[0][0] = 1;
  for (register int j = (1); j <= (n); j++)
    for (register int i = (j); i <= (n); i++)
      for (register int k = (1); k <= (i); k++)
        g[j][i] = (g[j][i] + 1LL * g[j - 1][i - k] * fac[k]) % mo;
  f[1] = 1;
  f[2] = 2;
  for (register int i = (3); i <= (n); i++) {
    f[i] = fac[i];
    for (register int j = (2); j <= (i - 1); j++)
      f[i] = (f[i] - 1LL * g[j][i] * f[j] + 1LL * mo * mo) % mo;
  }
  for (register int i = (3); i <= (n); i++)
    f[i] = (1LL * f[i] + (i & 1 ? 2 : -2) + mo) % mo;
  while (T--) {
    int x;
    read(x);
    printf("%d\n", f[x]);
  }
  return 0;
}
