#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ls (o<<1)
#define rs (o<<1 | 1)
const int N = 1e5+10;
int MOD = 571373;
int n,q;
int a[N], t[N<<2], add[N<<2], mul[N<<2];
int mo(int x){
return (x%MOD + MOD) % MOD;
}
void update(int s,int e,int o, int k, int x){
t[o] = mo( mo(t[o]*k) + mo(x*(e-s+1)) );
mul[o] = mo(mul[o]*k%MOD);
add[o] = mo( mo(add[o]*k) + x );
}
void pushup(int o){
t[o] = mo(t[ls] + t[rs]);
}
void pushdown(int s, int e, int o){
int mid = (s+e) / 2;
update(s,mid,ls,mul[o],add[o]);
update(mid+1,e,rs,mul[o],add[o]);
mul[o] = 1;
add[o] = 0;
}
void build(int s=1, int e=n, int o=1){
mul[o] = 1;
if (s==e){
t[o] = a[s];
return;
}
int mid = (s+e) / 2;
build(s,mid,ls);
build(mid+1,e,rs);
pushup(o);
}
void modify(int l, int r, int k, int x, int s=1, int e=n, int o=1){
if ( l<=s && e<=r ){
update(s,e,o,k,x);
return;
}
pushdown(s,e,o);
int mid = (s+e) / 2;
if (l<=mid) modify(l,r,k,x,s,mid,ls);
if (mid+1<=r) modify(l,r,k,x,mid+1,e,rs);
pushup(o);
}
int query(int l, int r, int s=1, int e=n, int o=1){
if ( l<=s && e<=r ){
return t[o];
}
pushdown(s,e,o);
int mid = (s+e) / 2;
int res = 0;
if ( l<=mid ) res = mo(res + query(l,r,s,mid,ls));
if ( mid+1<=r ) res = mo(res + query(l,r,mid+1,e,rs));
pushup(o);
return res;
}
signed main(){
cin >> n >> q >> MOD;
for ( int i=1; i<=n; i++ ) cin >> a[i];
build();
while(q--){
int op; cin >> op;
if(op==3){
int x,y; cin >> x >> y;
cout << query(x,y) << '\n';
} else if (op==1){
int x,y,k; cin >> x >> y >> k;
modify(x,y,k,0);
} else if (op==2){
int x,y,k; cin >> x >> y >> k;
modify(x,y,1,k);
}
}
return 0;
}