#include using namespace std; #include using namespace atcoder; typedef long long ll; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long mod=998244353LL,n,m,q; struct S{ ll value; ll length; S operator+(S other) { S ret; ret.value = (modpow(m,other.length,mod)*value+other.value)%mod; ret.length = length+other.length; return ret; } ll val(){ return value % mod; } }; S op(S a,S b){ return a+b; } S e(){ return {0LL,0LL}; } int main() { cin >> n >> m >> q; vector v(n); for(int i = 0;i < n;i++){ ll a;cin>>a;a--; v[i].value = a;v[i].length = 1; } segtree seg(v); for(int i = 0;i < q;i++){ ll l,r;cin>>l>>r;l--; cout << (seg.prod(l,r).val()+1)%mod << endl; } }