#include <bits/stdc++.h>
using namespace std;
long long t, fact[405], inv[405], dp[405][405], ans[405], n, dp2[405];
long long p;
long long exp(long long x, long long k) {
  if (k == 0) return 1;
  if (k % 2 == 1) return x * exp(x, k - 1) % p;
  long long y = exp(x, k / 2);
  return y * y % p;
}
int main() {
  cin >> t >> p;
  fact[0] = 1;
  for (int i = 1; i < 405; ++i) {
    fact[i] = i * fact[i - 1] % p;
    inv[i] = exp(i, p - 2);
  }
  dp[0][0] = 1;
  for (int i = 0; i <= 399; ++i)
    for (int k = 1; k <= 400; ++k)
      for (int j = 0; j <= 400 - k; ++j)
        dp[j + k][i + 1] = (dp[j + k][i + 1] + fact[k] * dp[j][i]) % p;
  dp2[1] = dp2[2] = 1;
  for (int i = 3; i <= 400; ++i) {
    dp2[i] = fact[i];
    for (int j = 1; j < i; ++j)
      dp2[i] = (p + dp2[i] - dp2[j] * fact[i - j] % p) % p;
  }
  for (int i = 1; i <= 400; ++i) {
    ans[i] = fact[i];
    for (int j = 3; j < i; ++j) ans[i] = (ans[i] + p - dp[i][j] * ans[j]) % p;
    for (int j = 1; j <= i - 1; ++j)
      ans[i] = (ans[i] + p - 2 * dp2[j] * fact[i - j] % p) % p;
    ans[2] = 2;
  }
  for (int i = 0; i < t; ++i) {
    int x;
    cin >> x;
    cout << ans[x] << "\n";
  }
}
