#include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using namespace atcoder; using ll = long long; using p = pair; using mod = modint998244353; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } vector> RunLength(string s){ vector> R; int n = s.size(); int pre = 0; rep(i,n - 1){ if(s[i + 1] != s[i]){ R.push_back({s[i],i - pre + 1}); pre = i + 1; } } if(pre != n)R.push_back({s[n - 1],n - pre}); return R; } int op(int a,int b){return min(a,b);} int e(){return (int)1e9;} segtree seg(1); int main(){ int n,m,q;cin >> n >> m >> q; vector A(n); vector Mp(n,1),SA(n + 1,0); rep(i,n)cin >> A[i]; rep(i,n)A[i]--; mod m9 = m; rep(i,n - 1){ Mp[i + 1] = Mp[i]*m9; } for(int i = n;i > 0;i--){ SA[i - 1] = SA[i] + A[i - 1]*Mp[n - i]; } while(q--){ int l,r;cin >> l >> r; l--; int k = r - l; mod rr = SA[l] - SA[r]; mod ans = rr/Mp[n - r]; ans++; cout << ans.val() << endl; } }