#include <bits/stdc++.h>
int t, p;
int cn = 2, tn;
long long c[500];
const int spec[] = {1, 2, 0};
int main() {
  scanf("%d%d", &t, &p);
  c[1] = p - 1;
  for (; t--;) {
    scanf("%d", &tn);
    if (tn <= 3) {
      printf("%d\n", spec[tn - 1]);
      continue;
    }
    if (tn < cn) {
      printf("%lld\n", (c[tn] + ((tn & 1) ? (2) : (-2))) % p);
      continue;
    }
    for (int n = cn; n <= tn; ++n) {
      for (int i = 1; i < n - 1; ++i)
        c[n] =
            (c[n] +
             c[i + 1] * (((i + 1) * c[n - i] + (i + 2) * c[n - i - 1]) % p)) %
            p;
      c[n] = (c[n] - c[n - 1] - c[n - 1] + p + p) % p;
    }
    printf("%lld\n", (c[tn] + ((tn & 1) ? (2) : (-2))) % p);
    cn = tn + 1;
  }
}
