// нрмкршак 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0,f=0;
	for(;!isdigit(c);c=getchar())if(c=='-')f=1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint&operator =(int o){return x=o,*this;}
	modint&operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint&operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint&operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint&operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint&operator /=(modint o){return *this*=(o^=(mod-2));}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	modint operator -(){return x?mod-x:0;}
};

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 2000005
#define inf 0x3f3f3f3f

int n,q,x,kmax,Tes,qwq;
modint a[maxn];
modint t[maxn];

int m,len;
vector<modint>b[100];

modint ipw2[maxn],big[maxn];
inline modint ipow2(int x){
	x%=(mod-1);
	return ipw2[x&65535]*big[x/65536];
}

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
unsigned long long seed;

struct mat{
	modint a[205][205];
	friend mat operator *(mat a,mat b){
		mat c;
		For(i,1,len)For(k,1,len)For(j,1,len)c.a[i][j]+=a.a[i][k]*b.a[k][j];
		return c;
	}
}mt,pwm[64];

modint now[205],nxt[205];

void mul(int id){
	For(i,1,len)
		For(j,1,len)
			nxt[i]+=pwm[id].a[i][j]*now[j];
	For(i,1,len) now[i]=nxt[i],nxt[i]=0;
}

modint solve(int k)
{
	if(!k)return a[x];
	if(qwq) k=min(k,m);
	if(k<=m){
		modint res=b[k][1+((x-1)>>k)];
		return res;
	}
	k-=m;
	int xx=1+((x-1)>>(m+1));
	--k;
	if(!k){
		modint res=t[xx];
		return res;
	}
	memset(now,0,sizeof now); now[xx]=1;
	For(i,0,60)if(k>>i&1)mul(i);
	modint res=0;
	For(i,1,len) res+=now[i]*t[i];
	return res;
}

void work()
{
	n=read(),q=read(),x=read(),kmax=read();
	qwq=0;
	b[0].resize(n+1); For(i,1,n)a[i]=b[0][i]=read();
	if(Tes>=1 && Tes<=2){
		For(o,1,kmax-1){
			b[o].resize(n+1);
			For(i,1,n){
				int ii=(i+1)/2;
				b[o][i]=b[o-1][ii]+b[o-1][n-ii+1];
			}
		}
		int res=0;
		For(i,1,q){
			long long k = rd(seed) % kmax;
			modint out=b[k][x];
	//		cout<<"out "<<out.x<<' '<<k<<endl;
			out*=ipow2(k);
			res ^= out.x*i;
		}
		cout<<res<<'\n';
		return;
	}
	int tn=n; m=0;
	while(tn%2==0){
		++m; tn/=2; b[m].resize(tn+1);
		For(i,1,tn) b[m][i]=b[m-1][i]+b[m-1][tn*2+1-i];
	}
	if(tn==1) qwq=1;
	else {
		len=tn/2+1;
		For(i,1,len) t[i]=0;
		For(i,1,tn){
			if(i<=tn/2) t[i]+=b[m][i];
			else if(i==tn/2+1) t[len]=b[m][i]*2;
			else t[tn-i+1]+=b[m][i];
		}
	//	For(i,1,len)cout<<t[i].x<<' ';puts(" t");
		For(i,1,len)For(j,1,len)mt.a[i][j]=0;
		For(i,1,len){
			if(i<(len+1)/2) mt.a[i][i*2-1]=1,mt.a[i][i*2]=1;
			else if(i==(len+1)/2) mt.a[i][len]=2,mt.a[i][len-1]=1;
			else if(i==len) mt.a[i][1]=1;
			else{
				int j=len-i;
				mt.a[i][j*2]=1;
				mt.a[i][j*2+1]=1;
			}
		}
		pwm[0]=mt;
		For(i,1,60) pwm[i]=pwm[i-1]*pwm[i-1];
	}
	int res=0;
	For(i,1,q){
		long long k = rd(seed) % kmax;
		modint out=solve(k);
//		cout<<"out "<<out.x<<' '<<k<<endl;
		out*=ipow2(k);
		res ^= out.x*i;
	}//puts("QAQ");
	cout<<res<<'\n';
}

signed main()
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	ipw2[0]=1; ipw2[1]=1; ipw2[1]/=2;
	For(i,2,65536) ipw2[i]=ipw2[i-1]*ipw2[1];
	big[0]=1; big[1]=ipw2[65536];
	For(i,2,65536) big[i]=big[i-1]*big[1];
	Tes=read();
	int T=read();
	cin>>seed;
	while(T--)work();
	return 0;
}
/*
2 23 11344
18 10 3 500
114 514 19 19 810 13 41 98 24 54 12 54 65 76 119 32 535 23

2 23 11344
7 10 3 500
114 514 19 19 810 13 41
*/ 
