#include <bits/stdc++.h>
using namespace std;
const int maxn = 405;
int n;
long long mo;
long long fac[maxn];
void Pre(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mo;
}
long long xi[maxn], he[maxn], xison[maxn][maxn];
void dp(int n) {
  for (int i = 1; i <= n; i++) {
    he[i] = fac[i];
    for (int j = 1; j <= i - 1; j++)
      he[i] = (he[i] - he[j] * fac[i - j] % mo + mo) % mo;
  }
  xison[0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      for (int k = 1; k <= i; k++)
        (xison[i][j] += xison[i - k][j - 1] * fac[k]) %= mo;
  for (int i = 1; i <= n; i++) {
    xi[i] = fac[i];
    for (int j = 1; j <= i - 1; j++)
      xi[i] = (xi[i] - 2 * he[j] * fac[i - j] % mo + mo) % mo;
    for (int j = 4; j <= i - 1; j++)
      xi[i] = (xi[i] - xi[j] * xison[i][j] % mo + mo) % mo;
  }
}
int T;
int main() {
  scanf("%d %lld", &T, &mo);
  Pre(400);
  dp(400);
  while (T--) {
    scanf("%d", &n);
    if (n == 1)
      puts("1");
    else if (n == 2)
      puts("2");
    else if (n == 3)
      puts("0");
    else
      printf("%lld\n", xi[n]);
  }
}
