#include #include using namespace std; using mint = atcoder::modint998244353; template struct prefixsum { int n; vector s; prefixsum() {} prefixsum(vector a) : n(a.size()), s(n + 1) { for (int i = 0; i < n; i++) { s[i + 1] = s[i] + a[i]; } } //[l, r) T get(int l, int r) { return s[r] - s[l]; } }; int main() { int n, m, q; cin >> n >> m >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } vector cnt(n); mint cur = 1; for (int i = n - 1; i >= 0; i--) { cnt[i] = mint(a[i]) * cur; cur *= mint(m); } prefixsum s(cnt); while (q--) { int l, r; cin >> l >> r; l--; mint ans = s.get(l, r) / mint(m).pow(n - r) + mint(1); cout << ans.val() << endl; } }