RT
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
#define LL long long
#define ULL unsigned long long
#define cint const int
using namespace std;
cint INTINF=0x7f7f7f7f;
const LL LLINF=9e18;
cint N=3e5+10;
LL a[N],d[N],lazy1[N],lazy2[N],mod;
inline LL read(){
LL x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void build(cint s,cint t,cint p){
lazy1[p]=1;
if(s==t){
d[p]=a[s]%mod;
return ;
}
LL m=s+((t-s)>>1);
build(s,m,p*2),build(m+1,t,p*2+1);
d[p]=(d[p*2]+d[p*2+1])%mod;
return ;
}
void pushdown(cint s,cint t,cint p){
LL m=(s+t)>>1;
if(lazy1[p]!=1){
lazy1[p*2]=(lazy1[p*2]*lazy1[p])%mod;
lazy1[p*2+1]=(lazy1[p*2+1]*lazy1[p])%mod;
lazy2[p*2]=(lazy2[p*2]*lazy2[p])%mod;
lazy2[p*2+1]=(lazy2[p*2+1]*lazy2[p])%mod;
d[p*2]=(d[p*2]*d[p])%mod;
d[p*2+1]=(d[p*2+1]*d[p])%mod;
lazy1[p]=1;
}
if(lazy2[p]){
d[p*2]=(d[p*2]+lazy2[p]*(m-s+1))%mod;
d[p*2+1]=(d[p*2+1]+lazy2[p]*(t-m))%mod;
lazy2[p*2]=(lazy2[p*2]+lazy2[p])%mod;
lazy2[p*2+1]=(lazy2[p*2+1]+lazy2[p])%mod;
lazy2[p]=0;
}
return ;
}
void update1(cint l,cint r,LL c,cint s,cint t,cint p){
if(l<=s&&t<=r){
lazy1[p]=(c*lazy1[p])%mod;
lazy2[p]=(c*lazy2[p])%mod;
d[p]=(c*d[p])%mod;
return ;
}
pushdown(s,t,p);
LL m=s+((t-s)>>1);
if(l<=m){
update1(l,r,c,s,m,p*2);
}
if(r>m){
update1(l,r,c,m+1,t,p*2+1);
}
d[p]=(d[p*2]+d[p*2+1])%mod;
return ;
}
void update2(cint l,cint r,cint c,cint s,cint t,cint p){
if(l<=s&&t<=r){
d[p]=((t-s+1)*c+d[p])%mod,lazy2[p]=(lazy2[p]+c)%mod;
return ;
}
LL m=s+((t-s)>>1);
pushdown(s,t,p);
if(l<=m){
update2(l,r,c,s,m,p*2);
}
if(r>m){
update2(l,r,c,m+1,t,p*2+1);
}
d[p]=(d[p*2]+d[p*2+1])%mod;
return ;
}
LL get_sum(cint l,cint r,cint s,cint t,cint p){
if(l<=s&&t<=r){
return d[p];
}
LL m=s+((t-s)>>1),sum=0;
pushdown(s,t,p);
if(l<=m){
sum=(sum+get_sum(l,r,s,m,p*2))%mod;
}
if(r>m){
sum=(sum+get_sum(l,r,m+1,t,p*2+1))%mod;
}
return sum%mod;
}
void solve(){
cint n=read(),m=read();
mod=read();
for(int i=1;i<=n;i++)
a[i]=read();
build(1,n,1);
for(int i=1;i<=m;i++)
{
cint op=read();
if(op==1)
{
cint x=read(),y=read(),k=read();
update1(x,y,k,1,n,1);
}
else if(op==2)
{
cint x=read(),y=read(),k=read();
update2(x,y,k,1,n,1);
}
else
{
cint x=read(),y=read();
cout<<get_sum(x,y,1,n,1)%mod<<endl;
}
}
return ;
}
int main()
{
#ifdef dbq
freopen("P3373.in","r",stdin);
freopen("P3373.out","w",stdout);
#endif
solve();
return 0;
}