#include <iostream>
#include <fstream>
using namespace std;
unsigned long long n, m, p, c;
unsigned long long a[50010];
unsigned long long kasumi(unsigned long long x, unsigned long long y){
unsigned long long res = 1;
while(y){
if(y & 1){
res *= x;
}
x *= x;
y >>= 1;
}
return res;
}
int main(){
freopen("verbinden.in", "r", stdin);
freopen("verbinden.out", "w", stdout);
cin >> n >> m >> p >> c;
for(unsigned long long i = 1; i <= n; i++) cin >> a[i];
while(m--){
unsigned long long op, l, r;
cin >> op >> l >> r;
if(op){
unsigned long long sum = 0;
for(unsigned long long i = l; i <= r; i++) (sum += a[i]) %= p;
cout << sum % p << endl;
}else{
for(unsigned long long i = l; i <= r; i++) a[i] = kasumi(c, a[i]);
}
}
return 0;
}