#include const int Mod = 998244353; long long div_mod(long long x, long long y, long long z) { if (x % y == 0) return x / y; else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y; } long long pow_mod(int n, int k, int M) { long long N, ans = 1; for (N = n; k > 0; k >>= 1, N = N * N % M) if (k & 1) ans = ans * N % M; return ans; } void merge_sort(int x[], int n) { static int y[1000] = {}; if (n <= 1) return; merge_sort(&(x[0]), n/2); merge_sort(&(x[n/2]), (n+1)/2); int i, p, q; for (i = 0, p = 0, q = n/2; i < n; i++) { if (p >= n/2) y[i] = x[q++]; else if (q >= n) y[i] = x[p++]; else y[i] = (x[p] < x[q])? x[p++]: x[q++]; } for (i = 0; i < n; i++) x[i] = y[i]; } int main() { int i, N, M, B[100001], C[100001]; scanf("%d %d", &N, &M); for (i = 1; i <= N; i++) scanf("%d %d", &(B[i]), &(C[i])); int j, k, div[1000], par[40010]; M--; for (i = 1, k = 0; i * i <= M; i++) { if (M % i != 0) continue; div[k++] = i; if (M / i != i) div[k++] = M / i; } M++; merge_sort(div, k); for (i = 1; i < M; i++) { for (j = 0; j < k; j++) if (pow_mod(i, div[j], M) == 1) break; if ((M - 1) / div[j] % 2 == 0) par[i] = 0; else par[i] = 1; } long long d_fact[3] = {(long long)M * (M - 1) % Mod, (long long)M * (M - 1) % Mod - 1, 1}, tmp = d_fact[0] - 2; printf("1\n"); if (B[1] == B[2] && C[1] == C[2]) printf("0\n"); else printf("%lld\n", d_fact[0]); for (i = 2, j = 0, d_fact[0] = d_fact[0] * div_mod(1, 2, Mod) % Mod; i < N; i++, j ^= 1) { d_fact[j] = d_fact[j] * (tmp--) % Mod; if (tmp < 0) tmp += Mod; if (j == 0) printf("%lld\n", d_fact[0] * d_fact[1] % Mod); else { d_fact[2] = d_fact[2] * i % Mod; if (par[C[i+1]] == 0) printf("%lld\n", d_fact[0] * (d_fact[1] + d_fact[2]) % Mod); else printf("%lld\n", d_fact[0] * (d_fact[1] + Mod - d_fact[2]) % Mod); } } fflush(stdout); return 0; }