#include<bits/stdc++.h>
using namespace std;
unsigned long long n,m,p,c,a[50005],s[50005];
unsigned long long ksm(unsigned long long p,unsigned long long x,unsigned long long p1) {
unsigned long long ans=1;
while(p1!=0) {
if(p1%2) {
ans*=p;
}
p*=p;
p1/=2;
}
return ans;
}
int main() {
freopen("verbinden.in","r",stdin);
freopen("verbinden.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m>>p>>c;
for(unsigned long long i=1; i<=n; i++) {
cin>>a[i];
s[i]=s[i-1]+a[i];
s[i]%=p;
}
while(m--) {
unsigned long long op,l,r;
cin>>op>>l>>r;
if(op==1) {
cout<<(s[r]-s[l-1])%p<<'\n';
} else {
for(unsigned long long i=l; i<=r; i++) {
a[i]=ksm(c,p,a[i]);
}
for(unsigned long long i=l; i<=n; i++) {
s[i]=s[i-1]+a[i];
s[i]%=p;
}
}
}
return 0;
}