#include<bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define fi first
#define se second
#define int long long
int read(){
	char ch=getchar();int x=0;bool f=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
	for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
	if(f)x=-x;return x;
}
const int maxn=2e6+5,mod=998244353;
int n,m,x,q,k_max,a[maxn],ans[maxn],b[maxn];
int test,T,tot=0;
unsigned long long seed;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
struct Mat{
	int a[77][77];
	Mat(){memset(a,0,sizeof a);}
}A,B,D;int p=0;
struct Mat2{
	int a[3][3];
	Mat2(){memset(a,0,sizeof a);}
}A1,B1,D1;
Mat operator * (Mat A,Mat B){
	Mat C;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				C.a[i][j]=(C.a[i][j]+A.a[i][k]*B.a[k][j])%mod,p++;
	return C;
}
Mat2 operator * (Mat2 A,Mat2 B){
	Mat2 C;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				C.a[i][j]=(C.a[i][j]+A.a[i][k]*B.a[k][j])%mod,p++;
	return C;
}
void Pow(int y){while(y){if(y&1)A=A*B;B=B*B;y=y/2;}}
inline void Pow2(int y){while(y){if(y&1)A1=A1*B1;B1=B1*B1;y=y/2;}}
void init(){
	ans[0]=a[x];
	while(n%2==0){
		for(int i=1;i<=n/2;i++)a[i]=(a[i]+a[n-i+1])*(mod/2+1)%mod;
		x=(x+1)/2;ans[++tot]=a[x];n=n/2;
	}
	for(int i=1;i<=n;i++)
		D.a[i-1][(i+1)/2-1]+=(mod/2+1),D.a[i-1][n-(i+1)/2]+=(mod/2+1),D.a[i-1][n-(i+1)/2]%=mod;
}
void init1(){
	for(int i=1;i<=n;i++)
		D1.a[i-1][(i+1)/2-1]+=(mod/2+1),D1.a[i-1][n-(i+1)/2]+=(mod/2+1),D1.a[i-1][n-(i+1)/2]%=mod;
}
void init2(){
	ans[0]=a[x];
	for(int i=1;i<=k_max;i++){
		for(int j=1;j<=n;j++)
			b[j]=(a[(j+1)/2]+a[n-(j+1)/2+1])*(mod/2+1)%mod;
		for(int j=1;j<=n;j++)a[j]=b[j];
		ans[i]=b[x];
	}tot=k_max;
}
inline int solve(int z){
	if(z<=tot)return ans[z];
	int y=z-tot;int s=0;
	if(n==1)return a[x];
	if(n>3)
	{
		B=A=D,Pow(y-1);
		for(int i=0;i<n;i++)
			s+=a[i+1]*A.a[x-1][i],s%=mod;
	}
	else {
		B1=A1=D1,Pow2(y-1);
		for(int i=0;i<n;i++)
			s+=a[i+1]*A1.a[x-1][i],s%=mod;
	}
	return s;
}
signed main(){
	freopen("noodle.in","r",stdin);	
	freopen("noodle.out","w",stdout);
	scanf("%lld%lld%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) {
		scanf("%lld%lld%lld%lld", &n, &q, &x, &k_max);
		for(int i = 1; i <= n; i ++)a[i]=read();
		if(test<=2) init2();
		else init();
		if(n<=3)init1();
		int res=0;
		for(int i = 1; i <= q; i ++) {
			int k = rd(seed) % k_max;
			res=res^(i*solve(k));
		}
		cout<<res<<endl;
	}
	return 0;
}
