#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool s;
const ll mod=998244353;
ll a[55][2000005];
ll b[2000005];
int lim;
bool t;

ll power(ll a,ll p){
	ll res=1;
	while(p){
		if(p&1)res=res*a%mod;
		p>>=1;
		a=a*a%mod;
	}
	return res;
}

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

vector<int> vec;

ll work(ll x){
	if(x==-1)return 0;
	else if(x&1)return (mod-(power(mod-2,x+1)-1)*power(mod-3,mod-2)%mod)%mod;
	else return (power(mod-2,x+1)-1)*power(mod-3,mod-2)%mod;
}

ll solve(ll A,ll B,int pos,int n,int x,ll k){
	if(pos==n)return A;
	int k1=k%vec.size();
	if(x<=vec[k1])return (work(k)*A%mod+work(k-1)*B%mod)%mod*power(power(2,mod-2),k)%mod;
	else return (work(k-1)*A%mod+work(k-2)*B%mod)%mod*power(power(2,mod-2),k-1)%mod;
}

int main(){
//	printf("%.2lf\n",(&s-&t)/1024.0/1024.0);
	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++){
		int n,q,x;
		long long k_max;
		scanf("%d%d%d%lld",&n,&q,&x,&k_max);
		for(int i=1;i<=n;i++)scanf("%lld",&a[0][i]);
		ll inv2=power(2,mod-2);
		int pos=0;
		for(lim=1;;lim++){
			for(int i=1;i<=n/2;i++)b[i]=(a[lim-1][i]+a[lim-1][n-i+1])%mod*inv2%mod;
			for(int i=1;i<=n;i++)a[lim][i]=b[(i+1)/2];
			int flag=2;
			for(int i=1;i<n;i++)if(a[lim][i]!=a[lim][i+1])flag--;
			if(flag>0){
				if(flag==1)for(int i=1;i<n;i++)if(a[lim][i]!=a[lim][i+1])pos=i;
				if(pos%2==0||flag==2)break;
			}
		}
//		printf("pos=%d lim=%d\n",pos,lim);
//		for(int i=1;i<=n;i++)printf("%lld ",a[lim][i]);puts("");
		vec.clear();
		do{
			vec.push_back(pos);
			pos=min(pos,n-pos)*2;
		}while(pos!=vec[0]&&pos<n);
		if(pos==n){
			for(;;lim++){
				for(int i=1;i<=n/2;i++)b[i]=(a[lim-1][i]+a[lim-1][n-i+1])%mod*inv2%mod;
				for(int i=1;i<=n;i++)a[lim][i]=b[(i+1)/2];
				int flag=2;
				for(int i=1;i<n;i++)if(a[lim][i]!=a[lim][i+1])flag--;
				if(flag==2)break;
			}
		}
//		printf("pos=%d lim=%d\n",pos,lim);
//		for(int i=1;i<=n;i++)printf("%lld ",a[lim][i]);puts("");
		ll res=0;
		for(int i=1;i<=q;i++){
			ll k=rd(seed)%k_max;
//			ll k;scanf("%lld",&k);
			ll ans;
			if(k<=lim)ans=a[k][x];
			else ans=solve(a[lim][1],a[lim][n],pos,n,x,k-lim);
//			printf("i=%d k=%lld ans=%lld\n",i,k,ans);
			res^=i*ans;
		}
		printf("%lld\n",res);
	}
	return 0;
}
