#include <bits/stdc++.h>
using namespace std;
long long int dp[405], fac[405];
long long int dp2[405];
long long int way[405][405];
int main() {
  int T, MOD;
  scanf("%d %d", &T, &MOD);
  fac[0] = 1;
  for (int i = 1; i < 405; i++) fac[i] = fac[i - 1] * (long long int)i % MOD;
  way[0][0] = 1;
  for (int i = 1; i < 405; i++) {
    for (int j = 1; j < 405; j++) {
      for (int k = 1; k <= i; k++) {
        way[i][j] += way[i - k][j - 1] * fac[k] % MOD;
        if (way[i][j] >= MOD) way[i][j] -= MOD;
      }
    }
    dp[i] = fac[i];
    for (int j = 3; j < i; j++) {
      dp[i] -= way[i][j] * dp[j] % MOD;
      if (dp[i] < 0) dp[i] += MOD;
    }
    if (i > 2) {
      for (int j = 1; j < i; j++) {
        dp[i] -= 2LL * fac[j] * dp2[i - j] % MOD;
        if (dp[i] < 0) dp[i] += MOD;
      }
    }
    dp2[i] = fac[i];
    for (int j = 1; j < i; j++) {
      dp2[i] -= fac[j] * dp2[i - j] % MOD;
      if (dp2[i] < 0) dp2[i] += MOD;
    }
  }
  while (T--) {
    int n;
    scanf("%d", &n);
    printf("%lld\n", dp[n]);
  }
  return 0;
}
