#include<iostream>
#include<cstdio>
using namespace std;
long long a[400005],t[400005],lazy_tag[400005],lazy_tag1[400005];
int mod;
inline int left_son(int x)
{
return x<<1;
}
inline int right_son(int x)
{
return x<<1|1;
}
inline void push_up_sum(int x)
{
t[x]=t[left_son(x)]+t[right_son(x)]%mod;
return ;
}
inline void build(int l,int r,int now)
{
lazy_tag[now]=0,lazy_tag1[now]=1;
if(l==r){t[now]=a[l]%mod;return ;}
int mid=(l+r)>>1;
build(l,mid,left_son(now));
build(mid+1,r,right_son(now));
push_up_sum(now);
return ;
}
inline void change_of_sum(int now,int l,int r,int k)
{
lazy_tag[now]+=k;
t[now]+=k*(r-l+1);
return ;
}
inline void push_down(int now,int l,int r)
{
long long mid=(l+r)>>1;
change_of_sum(left_son(now),l,mid,lazy_tag[now]);
change_of_sum(right_son(now),mid+1,r,lazy_tag[now]);
lazy_tag[now]=0;
return ;
}
inline void update(int now,int l,int r,int k,int x,int y)
{
if(x<=l&&r<=y)
{
t[now]+=k*(r-l+1);
lazy_tag[now]+=k;
return ;
}
push_down(now,l,r);
int mid=(l+r)>>1;
if(x<=mid) update(left_son(now),l,mid,k,x,y);
if(mid<y) update(right_son(now),mid+1,r,k,x,y);
push_up_sum(now);
return ;
}
inline long long ask(int now,int l,int r,int x,int y)
{
long long ans=0;
if(x<=l&&r<=y)
{
return t[now];
}
push_down(now,l,r);
int mid=(l+r)>>1;
if(x<=mid) ans+=ask(left_son(now),l,mid,x,y);
if(mid<y) ans+=ask(right_son(now),mid+1,r,x,y);
return ans;
}
inline void change_of_times(int now,int l,int r,int k)
{
t[now]=k*t[now]%mod;
lazy_tag1[now]=lazy_tag1[now]*k%mod;
return ;
}
inline void push_down1(int now,int l,int r)
{
long long mid=(l+r)>>1;
change_of_times(left_son(now),l,mid,lazy_tag1[now]);
change_of_times(right_son(now),mid+1,r,lazy_tag1[now]);
lazy_tag1[now]=1;
return ;
}
inline void update1(int now,int l,int r,int k,int x,int y)
{
if(x<=l&&r<=y)
{
t[now]=k*t[now]%mod;
lazy_tag1[now]=lazy_tag1[now]*k%mod;
return ;
}
push_down1(now,l,r);
int mid=(l+r)>>1;
if(x<=mid) update1(left_son(now),l,mid,k,x,y);
if(mid<y) update1(right_son(now),mid+1,r,k,x,y);
push_up_sum(now);
return ;
}
int main()
{
int n,m;
scanf("%d%d%d",&n,&m,&mod);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
build(1,n,1);
while(m--)
{
int tag;
scanf("%d",&tag);
if(tag==2)
{
int x,y,k;
scanf("%d%d%d",&x,&y,&k);
update(1,1,n,k,x,y);
}
else if(tag==1)
{
int x,y,k;
scanf("%d%d%d",&x,&y,&k);
update1(1,1,n,k,x,y);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
printf("%lld\n",ask(1,1,n,x,y)%mod);
}
}
return 0;
}