#include <bits/stdc++.h>
using namespace std;
const int N = 401;
int n, mod;
int dp[N], way[N][N], fact[N], ans[N];
void add(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}
void sub(int &x, int y) {
  x -= y;
  if (x < 0) {
    x += mod;
  }
}
int mul(int x, int y) { return (1ll * x * y) % mod; }
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int i, j, k, l;
  cin >> n >> mod;
  fact[0] = 1;
  for (i = 1; i < N; i++) {
    fact[i] = mul(i, fact[i - 1]);
  }
  dp[1] = 1;
  for (i = 2; i < N; i++) {
    dp[i] = fact[i];
    for (j = 1; j < i; j++) {
      sub(dp[i], mul(dp[j], fact[i - j]));
    }
  }
  way[0][0] = 1;
  for (i = 1; i < N; i++) {
    for (j = 1; j < N; j++) {
      for (k = 1; k <= j; k++) {
        add(way[i][j], mul(way[i - 1][j - k], fact[k]));
      }
    }
  }
  ans[1] = 1;
  for (i = 2; i < N; i++) {
    ans[i] = fact[i];
    for (j = 1; j < i; j++) {
      sub(ans[i], mul(dp[j], fact[i - j]));
      sub(ans[i], mul(dp[j], fact[i - j]));
    }
    for (j = 3; j < i; j++) {
      sub(ans[i], mul(ans[j], way[j][i]));
    }
  }
  ans[2] = 2;
  for (i = 1; i <= n; i++) {
    cin >> j;
    cout << ans[j] << '\n';
  }
}
