#include <bits/stdc++.h>
using namespace std;
int T, Mod, n, fac[410], g[410], dp[410][410], ans[410];
int main() {
  cin >> T >> Mod;
  fac[0] = 1;
  for (int i = 1; i <= 400; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
  g[1] = 1, g[2] = 1;
  for (int i = 3; i <= 400; i++) {
    g[i] = fac[i];
    for (int j = 1; j < i; j++) g[i] = (g[i] - 1ll * g[j] * fac[i - j]) % Mod;
    if (g[i] < 0) g[i] += Mod;
  }
  dp[0][0] = 1;
  for (int k = 1; k <= 400; k++)
    for (int i = k; i <= 400; i++)
      for (int j = k - 1; j < i; j++)
        dp[k][i] = (dp[k][i] + 1ll * dp[k - 1][j] * fac[i - j]) % Mod;
  ans[1] = 1, ans[2] = 2, ans[3] = 0, ans[4] = 2;
  for (int i = 5; i <= 400; i++) {
    ans[i] = fac[i];
    for (int j = 3; j < i; j++)
      ans[i] = (ans[i] - 1ll * ans[j] * dp[j][i]) % Mod;
    for (int j = 1; j < i; j++)
      ans[i] = (ans[i] - 2ll * g[j] * fac[i - j]) % Mod;
    if (ans[i] < 0) ans[i] += Mod;
  }
  for (; T; T--) {
    cin >> n;
    cout << ans[n] << endl;
  }
  return 0;
}
