#include<bits/stdc++.h>
#define ll long long
#define N 2000007
using namespace std;
ll n,mm,P,a[100007],d[N],b[N],c[N];
inline ll ls(ll x)
{
return x<<1;
}
inline ll rs(ll x)
{
return x<<1|1;
}
inline void pushup(ll p)
{
d[p]=(d[ls(p)]+d[rs(p)])%P;
}
inline void build(ll s,ll t,ll p)
{
c[p]=1;
if(s==t) {d[p]=a[s];return ;}
ll m=s+((t-s)>>1);
build(s,m,ls(p));
build(m+1,t,rs(p));
pushup(p);
}
inline void pushdown(ll s,ll t,ll p)
{
ll m=s+((t-s)>>1);
d[ls(p)]=(d[ls(p)]*c[p]+b[p]*(m-s+1))%P;
d[rs(p)]=(d[rs(p)]*c[p]+b[p]*(t-m))%P;
c[ls(p)]=(c[ls(p)]*c[p])%P;
c[rs(p)]=(c[rs(p)*c[p]])%P;
b[ls(p)]=(b[ls(p)]*c[p]+b[p])%P;
b[rs(p)]=(b[rs(p)]*c[p]+b[p])%P;
c[p]=1;
b[p]=0;
return ;
}
inline void update1(ll l,ll r,ll cc,ll s,ll t,ll p)
{
if(l<=s&&t<=r){
d[p]=(d[p]*cc)%P;
c[p]=(c[p]*cc)%P;
b[p]=(b[p]*cc)%P;
return ;
}
pushdown(s,t,p);
ll m=s+((t-s)>>1);
if(m>=l) update1(l,r,cc,s,m,ls(p));
if(m<r) update1(l,r,cc,m+1,t,rs(p));
pushup(p);
return ;
}
inline void update2(ll l,ll r,ll cc,ll s,ll t,ll p)
{
if(l<=s&&t<=r){
b[p]=(b[p]+cc)%P;
d[p]=(d[p]+(t-s+1)*cc)%P;
return ;
}
pushdown(s,t,p);
ll m=s+((t-s)>>1);
if(l<=m) update2(l,r,cc,s,m,ls(p));
if(m<r) update2(l,r,cc,m+1,t,rs(p));
pushup(p);
return ;
}
inline ll getsum(ll l,ll r,ll s,ll t,ll p)
{
if(l<=s&&t<=r) return d[p];
pushdown(s,t,p);
ll m=s+((t-s)>>1);
ll tot=0;
if(m>=l) tot+=getsum(l,r,s,m,ls(p));
tot%=P;
if(m<r) tot+=getsum(l,r,m+1,t,rs(p));
tot%=P;
return tot;
}
inline ll read()
{
ll s=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*f;
}
int main()
{
n=read();
mm=read();
P=read();
for(ll i=1;i<=n;++i) cin>>a[i];
build(1,n,1);
while(mm--)
{
ll s,xx,y,k;
s=read();
xx=read();
y=read();
if(s==1)
{
k=read();
update1(xx,y,k,1,n,1);
}
else if(s==2)
{
k=read();
update2(xx,y,k,1,n,1);
}
else if(s==3)
{
printf("%lld\n",getsum(xx,y,1,n,1));
}
}
return 0;
}