#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
const int N = 1e5 + 7;
using namespace std;
typedef long long ll;
struct Tree{
int l, r;
ll sum;
ll lz;
ll lz2;
}t[N << 2];
int a[N];
int n, m;
long long R;
void build(int p, int l, int r)
{
t[p].l = l;
t[p].r = r;
t[p].lz2 = 1;
if(l == r)
{
t[p].sum = a[l] % R;
return ;
}
const int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
t[p].sum = (t[p << 1].sum + t[p << 1 | 1].sum) % R;
}
void sp(int p)
{
ll add = t[p].lz;
ll mul = t[p].lz2;
t[p << 1].sum = (t[p << 1].sum * mul + add * (t[p << 1].r - t[p << 1].l + 1)) % R;
t[p << 1 | 1].sum = (t[p << 1 | 1].sum * mul + add * (t[p << 1 | 1].r - t[p << 1 | 1].l + 1)) % R;
t[p << 1].lz2 = (t[p << 1].lz2 * mul) % R;
t[p << 1 | 1].lz2 = (t[p << 1 | 1].lz2 * mul) % R;
t[p << 1].lz = (t[p << 1].lz * mul + add) % R;
t[p << 1 | 1].lz = (t[p << 1 | 1].lz * mul + add) % R;
t[p].lz = 0;
t[p].lz2 = 1;
}
void ch1(int p, int x, int y, ll k)
{
int l = t[p].l;
int r = t[p].r;
if(x <= l && r <= y)
{
t[p].sum = (t[p].sum + k * (r - l + 1)) % R;
t[p].lz = (t[p].lz + k) % R;
return;
}
sp(p);
const int mid = (l + r) >> 1;
if(x <= mid)
{
ch1(p << 1, x, y, k);
}
if(y >= mid + 1)
{
ch1(p << 1 | 1, x, y, k);
}
t[p].sum = (t[p << 1].sum + t[p << 1 | 1].sum) % R;
}
void ch2(int p, int x, int y, ll k)
{
int l = t[p].l;
int r = t[p].r;
if(x <= l && r <= y)
{
t[p].sum = (t[p].sum * k) % R;
t[p].lz2 = (t[p].lz2 * k) % R;
t[p].lz = (t[p].lz * k) % R;
return ;
}
sp(p);
const int mid = (l + r) >> 1;
if(x <= mid)
{
ch2(p << 1, x, y, k);
}
if(y >= mid + 1)
{
ch2(p << 1 | 1, x, y, k);
}
t[p].sum = (t[p << 1].sum + t[p << 1 | 1].sum) % R;
}
ll ask(int p, int x, int y)
{
int l = t[p].l;
int r = t[p].r;
if(x <= l && r <= y)
{
return t[p].sum % R;
}
sp(p);
const ll mid = (l + r) >> 1;
ll val = 0;
if(x <= mid)
{
val = (val + ask(p << 1, x, y)) % R;
}
if(y >= mid + 1)
{
val = (val + ask(p << 1 | 1, x, y)) % R;
}
return val;
}
int main(){
scanf("%d%d%lld", &n, &m, &R);
for(int i = 1; i <= n; ++i)
{
scanf("%d", &a[i]);
}
build(1, 1, n);
for(int i = 1; i <= n; ++i)
{
int op, x, y; ll k;
scanf("%d%d%d", &op, &x, &y);
if(op == 3)
{
printf("%lld\n", ask(1, x, y));
}else{
scanf("%lld", &k);
if(op == 1)
{
ch2(1, x, y, k);
}else{
ch1(1, x, y, k);
}
}
}
return 0;
}