#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
int n;
ll b[2000020],bb[2000020];
struct nod{
	ll ju[155][155];
}nl,nll,ANS,base,c,y;
int check(int n){
	int nn=1;
	for(int i=1;i<=22;i++){
		if(n==nn) return 1;
		nn<<=1;
	}
	return 0;
}
nod Mul(nod a,nod b){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			c.ju[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				c.ju[i][j]=(c.ju[i][j]+a.ju[i][k]*b.ju[k][j])%mod;
			}
		}
	}
	return c;
}
nod ksm(nod a,ll b){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) ANS.ju[i][j]=0;
		ANS.ju[i][i]=1;
		for(int j=1;j<=n;j++){
			if((i+1)/2==j || (i+1)/2==n-j+1) base.ju[i][j]=1;
			else base.ju[i][j]=0;
		}
	}
	while(b>0){
		if(b&1){
			ANS=Mul(ANS,base);
		}
		base=Mul(base,base);
		b>>=1;
	}
	return ANS;
}
ll ksm1(ll a,ll b){
	ll ans=1,base=a;
	while(b>0){
		if(b&1){
			ans=ans*base%mod;
		}
		base=base*base%mod;
		b>>=1;
	}
	return ans;
}
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);
	for(int Case = 1; Case <= T; Case ++) {
		ll Ans=0;
		int q, x;
		long long k_max;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<ll> a(n + 1);
		for(int i = 1; i <= n; i ++) {
			scanf("%lld", &a[i]);
		}
//		cout<<"ok0"<<endl;
		for(int ii = 1; ii <= q; ii ++) {
			long long k = rd(seed) % k_max;
//			cout<<"ok"<<ii<<endl;
			if((k<=500 && n<=500) || k<=10){
				for(int i=1;i<=n;i++) b[i]=a[i];
				for(int ci=1;ci<=k;ci++){
					for(int i=1;i<=n;i++){
						bb[i]=(b[(i+1)/2]+b[n+1-(i+1)/2])%mod;
					}
					for(int i=1;i<=n;i++){
						b[i]=bb[i];
					}
				}
				Ans^=(b[x]*ksm1(2,mod-1-k)%mod*ii);
			}
			else if(check(n)){
				for(int i=1;i<=n;i++) b[i]=a[i];
				for(int ci=1;ci<=min(k,22ll);ci++){
					for(int i=1;i<=n;i++){
						bb[i]=(b[(i+1)/2]+b[n+1-(i+1)/2])%mod;
					}
					for(int i=1;i<=n;i++){
						b[i]=bb[i];
					}
				}
				Ans^=(b[x]*ksm1(2,mod-1-k)%mod*ii);
			}
			else{
				for(int i=1;i<=n;i++){
					for(int j=1;j<=n;j++){
						if((i+1)/2==j || (i+1)/2==n-j+1) y.ju[i][j]=1;
						else y.ju[i][j]=0;
					}
				}
				y=ksm(y,k);
				ll ans=0;
				for(int i=1;i<=n;i++){
					ans=(ans+y.ju[x][i]*a[i]);
				}
				ans=ans*ksm1(2,mod-1-k)%mod;
				Ans^=(ans*ii);
			}
//			cout<<Ans<<endl;
			/*
			Code your solution here.
			*/
		}
		cout<<Ans<<endl;
	}
}
