#include using namespace std; using ll = long long; using Vl = std::vector ; ll const m = 998244353; std::stack st1, st2; stack stt; int N, M, K; void Push(int a, int id = 1) { stack S = (id ? st2 : st1); Vl A(K, 0); if (S.empty()) { A[0] = 1; A[a] ++; } else { auto B = S.top(); for (int i = 0; i < K; i ++) { A[i] = B[i] + B[(i + K - a) % K]; A[i] %= m; } } S.push(A); if (id == 1) { stt.push(a); } } void Pop() { if (!st1.empty()) { st1.pop(); } else { while (!st2.empty()) { auto v = st2.top(); st2.pop(); auto a = stt.top(); Push(a, 0); } st1.pop(); } } void CA() { Vl A(K, 0), B(K, 0); if (st1.empty()) { A[0] = 1; } else { A = st1.top(); } if (st2.empty()) { B[0] = 1; } else { B = st2.top(); } ll ans = m - 1; for (int i = 0; i < K; i ++) { ans += (A[i] * B[(K - i) % K]) % m; ans %= m; } cout << ans << endl; } int main () { cin >> N >> M >> K; for (int i = 0; i < M - 1; i ++) { int a; cin >> a; Push(a); } for (int i = M - 1; i < N; i ++) { int a; cin >> a; Push(a); CA(); Pop(); } }