#include <bits/stdc++.h>
using namespace std;
const int N = 405;
int n = 400, T, mod, f[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> T >> mod, f[1] = 1;
  for (int i = (2); i <= (n); ++i) {
    for (int j = (1); j <= (i - 1); ++j)
      (f[i] += (long long)(j + 1) * f[j] % mod * f[i - j] % mod) %= mod;
    for (int j = (2); j <= (i - 1); ++j)
      (f[i] += (long long)j * f[j] % mod * f[i - j + 1] % mod) %= mod;
    f[i] = mod - f[i];
  }
  for (int i = (1); i <= (n); ++i) {
    f[i] = mod - f[i];
    if (i & 1)
      (f[i] += 2) %= mod;
    else
      (f[i] += mod - 2) %= mod;
  }
  f[2] = 2;
  while (T--) {
    int x;
    cin >> x, cout << f[x] << "\n";
  }
  return 0;
}
