#include using namespace std; const int MAX_N = 5000000; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; long long M; cin >> T >> M; vector fact(MAX_N + 1); if (M == 1) { while (T--) { int N; cin >> N; cout << "0\n"; } return 0; } fact[0] = 1 % M; for (int i = 1; i <= MAX_N; ++i) { fact[i] = (fact[i-1] * i) % M; } while (T--) { int N; cin >> N; if (N == 1) { cout << 1 % M << "\n"; } else { long long res = (4LL * fact[N] - 4LL) % M; if (res < 0) { res += M; } cout << res % M << "\n"; } } return 0; }