#include using i64 = long long; template T power(T a, i64 b) { T res = 1; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; } template struct MInt { int x; MInt() : x{} {} MInt(i64 x) : x{norm(x % P)} {} int norm(int x) const { if (x < 0) { x += P; } if (x >= P) { x -= P; } return x; } int val() const { return x; } MInt operator-() const { MInt res; res.x = norm(P - x); return res; } MInt inv() const { assert(x != 0); return power(*this, P - 2); } MInt &operator*=(const MInt &rhs) { x = 1LL * x * rhs.x % P; return *this; } MInt &operator+=(const MInt &rhs) { x = norm(x + rhs.x); return *this; } MInt &operator-=(const MInt &rhs) { x = norm(x - rhs.x); return *this; } MInt &operator/=(const MInt &rhs) { return *this *= rhs.inv(); } friend MInt operator*(const MInt &lhs, const MInt &rhs) { MInt res = lhs; res *= rhs; return res; } friend MInt operator+(const MInt &lhs, const MInt &rhs) { MInt res = lhs; res += rhs; return res; } friend MInt operator-(const MInt &lhs, const MInt &rhs) { MInt res = lhs; res -= rhs; return res; } friend MInt operator/(const MInt &lhs, const MInt &rhs) { MInt res = lhs; res /= rhs; return res; } friend std::istream &operator>>(std::istream &is, MInt &a) { i64 v; is >> v; a = MInt(v); return is; } friend std::ostream &operator<<(std::ostream &os, const MInt &a) { return os << a.val(); } }; constexpr int P = 998244353; using Z = MInt

; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k; std::cin >> n >> m >> k; std::vector a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::vector pre(n, std::vector(k)), suf(pre); for (int i = 0; i < n; i++) { if (i % m == 0) { pre[i][0] += 1; pre[i][a[i]] += 1; } else { pre[i] = pre[i - 1]; for (int j = 0; j < k; j++) { pre[i][(j + a[i]) % k] += pre[i - 1][j]; } } } for (int i = n - 1; i >= 0; i--) { if (i == n - 1 || i % m == m - 1) { suf[i][0] += 1; suf[i][a[i]] += 1; } else { suf[i] = suf[i + 1]; for (int j = 0; j < k; j++) { suf[i][(j + a[i]) % k] += suf[i + 1][j]; } } } for (int i = 0; i <= n - m; i++) { Z ans = 0; if (i % m == 0) { ans = suf[i][0]; } else { for (int j = 0; j < k; j++) { ans += suf[i][j] * pre[i + m - 1][(k - j) % k]; } } ans -= 1; std::cout << ans << "\n"; } return 0; }