#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; #include using namespace atcoder; using mint = modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,m,q; cin >> n >> m >> q; vector a(n); rep(i,n) { int x; cin >> x; a[i] = mint(x-1); } vector b(n,1); rep(i,n-1) b[i+1] = b[i]*m; rep(i,n){ a[i]/=b[i]; } vector sum(n+1,0); rep(i,n) sum[i+1] = sum[i]+a[i]; rep(_,q){ int l,r; cin >> l >> r; l--; int k = r-l; mint ans = (sum[r]-sum[l])*(b[l+k-1])+1; cout << ans.val() << endl; } }