#include <bits/stdc++.h>
using namespace std;
int N, P;
long long D[420], C[420][420], E[420], fact[420];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  N = 400;
  int t, p;
  cin >> t >> p;
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = (fact[i - 1] * i) % p;
    E[i] = fact[i];
    for (int j = 1; j < i; j++) E[i] -= (fact[j] * E[i - j]) % p;
    E[i] %= p;
    if (E[i] < 0) E[i] += p;
  }
  C[0][0] = 1;
  for (int j = 1; j <= N; j++) {
    for (int i = 1; i <= N; i++) {
      for (int k = 1; k <= i; k++) {
        C[i][j] = (C[i][j] + fact[k] * C[i - k][j - 1]) % p;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    D[i] = fact[i];
    for (int j = 1; j < i; j++) {
      D[i] -= (2 * fact[j] * E[i - j]) % p;
    }
    for (int j = 3; j < i; j++) {
      D[i] -= (D[j] * C[i][j]) % p;
    }
    D[i] %= p;
    if (D[i] < 0) D[i] += p;
    if (i == 2) D[i] = 2;
  }
  while (t--) {
    int n;
    cin >> n;
    cout << D[n] << '\n';
  }
}
