#include <bits/stdc++.h>
using namespace std;
const int N=21,Mod=998244353;
int n,ans[22][2000010],ans_[510][510];
unsigned long long rd(unsigned long long &x) 
{
	x^=(x<<13);
	x^=(x>>7);
	x^=(x<<17);
	return x ;
}
int ksm(int aa,int bb)
{
	int res=1;
	for (;bb;bb>>=1) {
		if (bb&1) res=1LL*res*aa%Mod;
		aa=1LL*aa*aa%Mod;
	}
	return res;
}
struct Matrix
{
	int M[151][151];
	Matrix() {
		memset(M,0,sizeof(M));
	}
	Matrix operator * (const Matrix &aa) const {
		Matrix res;
		memset(res.M,0,sizeof(res.M));
		for (int i=1;i<=n;i++)
		  for (int j=1;j<=n;j++)
		    for (int k=1;k<=n;k++)
		      res.M[i][j]+=1LL*M[i][k]*aa.M[k][j]%Mod,res.M[i][j]%=Mod;
		return res;
	}
}f,tr[61];
int read()
{
	char ch=getchar();
	int aqq=0,op=1;
	while (ch<'0'||ch>'9') {if (ch=='-') op=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') aqq=aqq*10+int(ch-48),ch=getchar();
	return aqq*op;
}
int main () 
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	int test,T;
	unsigned long long seed;
	scanf("%d%d%llu",&test,&T,&seed);
	int tmp=ksm(2,Mod-2);
	for (int Case=1;Case<=T;Case++) {
		int q,x;
		long long k_max;
		scanf("%d%d%d%lld",&n,&q,&x,&k_max);
		vector<int> a(n+1);
		for (int i=1;i<=n;i++) 
		  a[i]=read();
		long long res=0;
		if (test==1) {
			for (int i=1;i<=n;i++) ans_[0][i]=a[i];
			for (int i=1;i<=k_max;i++)
			  for (int j=1;j<=n;j++)
			    ans_[i][j]=1LL*(ans_[i-1][(j+1)/2]+ans_[i-1][n-(j+1)/2+1])%Mod*tmp%Mod;
			for (int i=1;i<=q;i++) {
				long long k=rd(seed)%k_max;
				res^=1LL*i*ans_[k][x];
			}
		}
		if (test==2||test==3) {
			for (int i=1;i<=n;i++) ans[0][i]=a[i];
			for (int i=1;i<=(k_max>N?N:k_max);i++) 
		  	  for (int j=1;j<=n;j++)
			    ans[i][j]=1LL*(ans[i-1][(j+1)/2]+ans[i-1][n-(j+1)/2+1])%Mod*tmp%Mod;
			for (int i=1;i<=q;i++) {
				long long k=rd(seed)%k_max;
				res^=1LL*i*ans[k>N?N:k][x];
			}
		}
		if (test>3) {
			memset(tr[0].M,0,sizeof(tr[0].M));
			for (int i=1;i<=n;i++)
			  tr[0].M[(i+1)/2][i]=tr[0].M[n-(i+1)/2+1][i]=tmp;
			for (int i=1;i<=60;i++)
			  tr[i]=tr[i-1]*tr[i-1];			
			for (int i1=1;i1<=q;i1++) {
				long long k=rd(seed)%k_max;
				for (int i=1;i<=n;i++) f.M[1][i]=a[i];
				for (int i=0;i<=60;i++)
				  if (k>>i&1) f=f*tr[i];
				res^=1LL*i1*f.M[1][x];
			}
		}
		printf("%lld\n",res);
	}
	return 0;
}
