#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  return (out << p.first << ' ' << p.second << endl);
}
const int INF = 1000000017;
const long long LLINF = 1000000000000000017LL;
const long double inf = 1.0 / 0.0;
const long double eps = 1e-10;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int N = 405;
long long first[N] = {};
long long dp[N][N] = {};
long long inv[N][N] = {};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int q, p;
  cin >> q >> p;
  first[0] = 1;
  for (int i = 1; i < N; ++i) {
    first[i] = first[i - 1] * i % p;
  }
  for (int n = 1; n < N; ++n) {
    dp[n][1] = first[n];
    for (int k = 2; k <= n; ++k) {
      for (int m = 0; m <= n - k; ++m) {
        dp[n][k] += first[m + 1] * dp[n - m - 1][k - 1];
        dp[n][k] %= p;
      }
    }
  }
  for (int n = 1; n < N; ++n) {
    for (int k = 1; k <= n; ++k) {
      long long cur = 0;
      for (int m = 1; m < n; ++m) {
        cur += dp[n][m] * inv[m][k];
        cur %= p;
      }
      inv[n][k] = ((n == k) - cur + p);
      if (inv[n][k] >= p) {
        inv[n][k] -= p;
      }
    }
  }
  while (q--) {
    int n;
    cin >> n;
    if (n == 2) {
      cout << 2 << '\n';
    } else {
      cout << ((-inv[n][1] + 2 * (n % 2 == 0 ? -1 : 1)) % p + p) % p << '\n';
    }
  }
  return 0;
}
