#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <cmath>
#include <ctime>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch>'9'||ch<'0') {if (ch=='-'){f=-1;} ch=getchar();}
while (ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
int n,m,k,pa,pb,ty,r,l;
long long ans=0;
int set[1001000]={};
void worka()
{
ans=set[l];
for (int i=l+1;i<=r;i++) {
ans*=set[i];if (ans>pa) ans%=pa;
}
cout<<ans<<endl;
}
long long get(int st)
{
long long tmp=1;
for (int i=1;i<=set[l];i++) {tmp*=k;if (tmp>pb)tmp%=pb;}
return tmp;
}
void workb()
{
ans=get(l);
long long tmp=0;
for (int i=l+1;i<=r;i++) {
tmp=ans;
for (int j=1;j<set[i];j++) {
ans*=tmp;if (ans>pb) ans%=pb;
}
}
cout<<ans<<endl;
}
int main()
{
freopen("chocolatebox.in","r",stdin);
freopen("chocolatebox.out","w",stdout);
n=read();m=read();k=read();pa=read();pb=read();
for (int i=1;i<=n;i++) set[i]=read();
for (int i=1;i<=m;i++){
ty=read();l=read();r=read();
if (ty==1) worka();
if (ty==2) workb();
}
return 0;
}