#include<bits/stdc++.h>
using namespace std;
#define N 2000005
#define mod 998244353
#define ll long long
#define ull unsigned ll
int type,t,n,q,x,a[N],b[N],ans[N];
ll k0,Ans;ull seed;
int read(){
	int x=0;char c=getchar();
	while ((c<'0')||(c>'9'))c=getchar();
	while ((c>='0')&&(c<='9'))x=x*10+c-'0',c=getchar();
	return x;
}
ull rd(ull &x){
	x^=(x<<13),x^=(x>>7),x^=(x<<17);
	return x;
}
int main(){
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	type=read(),t=read(),scanf("%llu",&seed);
	while (t--){
		n=read(),q=read(),x=read(),scanf("%lld",&k0);
		for(int i=1;i<=n;i++)a[i]=read();
		if (type<=2){
			ans[0]=a[x];
			for(int i=1;i<=k0;i++){
				for(int j=1;j<=n;j++)b[j]=a[j];
				for(int j=1;j<=n;j++)a[j]=(ll)(b[(j+1>>1)]+b[n-(j+1>>1)+1])*(mod+1>>1)%mod;
				ans[i]=a[x];
			}
			Ans=0;
			for(int i=1;i<=q;i++)Ans^=(ll)i*ans[rd(seed)%k0];
			printf("%lld\n",Ans);
			continue;
		}
		if (type==3){
			ans[0]=a[x];
			for(int i=1;i<=20;i++){
				for(int j=1;j<=n;j++)b[j]=a[j];
				for(int j=1;j<=n;j++)a[j]=(ll)(b[(j+1>>1)]+b[n-(j+1>>1)+1])*(mod+1>>1)%mod;
				ans[i]=a[x];
			}
			Ans=0;
			for(int i=1;i<=q;i++)Ans^=(ll)i*ans[min(rd(seed)%k0,(ull)20)];
			printf("%lld\n",Ans);
			continue;
		}
	}
	return 0;
}
