#include <bits/stdc++.h>
using namespace std;
long long ways[401][401];
int main() {
  long long n = 400;
  long long MOD;
  int T;
  cin >> T;
  cin >> MOD;
  vector<long long> fact(n + 1);
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
  vector<long long> inc(n + 1);
  inc[1] = 0;
  for (long long len = 1; len <= n; len++) {
    vector<long long> tmp(len + 1, 0);
    tmp[0] = 1;
    for (long long f = 1; f <= len; f++) {
      for (long long g = 1; g <= f; g++) {
        if (g == len) continue;
        tmp[f] += tmp[f - g] * (fact[g] - inc[g]);
        tmp[f] %= MOD;
      }
    }
    inc[len] = tmp[len];
  }
  vector<long long> ans(n + 1);
  ans[0] = 0;
  ways[0][0] = 1;
  for (long long a = 1; a <= n; a++) {
    for (long long b = 1; b <= n; b++) {
      for (long long c = 0; c < a; c++) {
        ways[a][b] += ways[c][b - 1] * fact[a - c];
        ways[a][b] %= MOD;
      }
    }
  }
  for (long long len = 1; len <= n; len++) {
    ans[len] = fact[len];
    ans[len] -= 2 * inc[len];
    for (long long cnt = 2; cnt < len; cnt++) {
      ans[len] -= ans[cnt] * ways[len][cnt];
      ans[len] %= MOD;
    }
  }
  ans[2] = 2;
  for (int t = 0; t < T; t++) {
    int nn;
    cin >> nn;
    long long f = ans[nn];
    f %= MOD;
    if (f < 0) f += MOD;
    cout << f << '\n';
  }
}
