#include #include using namespace std; using mint = atcoder::modint998244353; const int CombMAX = 3000000; std::vector fac(CombMAX + 1), finv(CombMAX + 1), inv(CombMAX + 1); struct Combinationinit { Combinationinit() { const int MOD = mint::mod(); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i <= CombMAX; i++) { fac[i] = fac[i - 1] * i; inv[i] = (mint)MOD - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } } Combinationinit_; int sum_pality; int main() { int n, m; cin >> n >> m; vector even_even, even_odd, odd_odd; auto convolution_init = [&]() { vector odd(n + 1), even(n + 1); for(int i = 0; i < n + 1; i++) { if(i % 2) odd[i] = finv[i] * finv[i]; else even[i] = finv[i] * finv[i]; } even_even = atcoder::convolution(even, even); even_odd = atcoder::convolution(even, odd); odd_odd = atcoder::convolution(odd, odd); }; vector quadratic_residue(m); auto quadratic_residue_init = [&]() { for(int i = 1; i < m; i++) quadratic_residue[(long long)i * i % m] = 1; }; convolution_init(); quadratic_residue_init(); vector b(n), c(n); auto decode_inversion = [&](int b, int c) { if(m == 2) return b == 1; return !quadratic_residue[c]; }; auto solver = [&](int k) -> mint { if(k == 1) return 1; if(k == 2) { if(b[0] == b[1] and c[0] == c[1]) return 0; return fac[m]; } if(k % 2) { return even_odd[k] * fac[k] * fac[k] * fac[k] / 4; } else { if(sum_pality % 2) return odd_odd[k] * fac[k] * fac[k] * fac[k] / 4; else return even_even[k] * fac[k] * fac[k] * fac[k] / 4; } }; for(int i = 0; i < n; i++) cin >> b[i] >> c[i]; for(int i = 1; i <= n; i++) { sum_pality += decode_inversion(b[i - 1], c[i - 1]); cout << solver(i).val() << '\n'; } return 0; }