#include <bits/stdc++.h>
using namespace std;
int const N = 400;
int md, fc[N + 1], dp[N + 1][N + 1], an[N + 1], sad[N + 1];
void ad(int &x, int y) {
  if ((x += y) >= md) x -= md;
}
void sb(int &x, int y) {
  if ((x -= y) < 0) x += md;
}
void solve() {
  fc[0] = 1;
  for (int i = 1; i < (int)(N + 1); ++i) fc[i] = (long long)fc[i - 1] * i % md;
  dp[0][0] = 1;
  for (int i = 0; i < (int)(N); ++i)
    for (int j = i; j < (int)(N); ++j)
      for (int k = 1; k < (int)(N - j + 1); ++k)
        ad(dp[i + 1][j + k], (long long)dp[i][j] * fc[k] % md);
  for (int i = 1; i < (int)(N + 1); ++i) {
    sad[i] = fc[i];
    for (int j = 1; j < (int)(i); ++j)
      sb(sad[i], (long long)sad[j] * fc[i - j] % md);
  }
  for (int i = 1; i < (int)(N + 1); ++i) an[i] = fc[i];
  for (int i = 3; i < (int)(N + 1); ++i) {
    for (int j = 1; j < (int)(i); ++j) {
      int s = fc[j];
      for (int k = 1; k < (int)(j); ++k)
        sb(s, (long long)sad[k] * fc[j - k] % md);
      sb(an[i], 2ll * s * fc[i - j] % md);
    }
    for (int j = 3; j < (int)(i); ++j)
      sb(an[i], (long long)an[j] * dp[j][i] % md);
  }
}
int main() {
  int t;
  scanf("%d%d", &t, &md);
  solve();
  while (t--) {
    int t;
    scanf("%d", &t);
    printf("%d\n", an[t]);
  }
}
