#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int inv2=(mod+1)/2;
const int N=2000010;
const int M=510;
int v[2][N],res[M],a[N];
unsigned long long rd(unsigned long long &x){
	x^=(x<<13);x^=(x>>7);x^=(x<<17);return x;
}
int mul(int x,int y){
	return 1LL*x*y%mod;
}
int add(int x,int y){
	return x+y>=mod?x+y-mod:x+y;
}
int getinv(int x){
	if (x==0) return 0;
	else if (x==1) return 1;
	else return mul(mod-mod/x,getinv(mod%x));
}
void getres(int km,int n,int x){
	int cur=0;
	for (int i=1;i<=n;++i) v[cur][i]=a[i];res[0]=a[x];
	for (int i=0;i<=km-1;++i){
		for (int j=1;j<=n;++j) v[cur^1][j]=0;
		for (int j=1;j<=n/2;++j){
			v[cur^1][j*2-1]=add(v[cur^1][j*2-1],mul(v[cur][j],inv2));
			v[cur^1][j*2]=add(v[cur^1][j*2],mul(v[cur][j],inv2));
		}
		for (int j=n/2+1;j<=n;++j){
			int k=n-j+1;
			v[cur^1][k*2-1]=add(v[cur^1][k*2-1],mul(v[cur][j],inv2));
			v[cur^1][k*2]=add(v[cur^1][k*2],mul(v[cur][j],inv2));
		}
		res[i+1]=v[cur^1][x];
		cur^=1;
	}	
}
signed 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);
	while (T --> 0){
		int n,q,x;long long km;
		scanf("%d%d%d%lld",&n,&q,&x,&km);
		for (int i=1;i<=n;++i) scanf("%d",&a[i]);
		if (km<=500){
			getres(km,n,x);
			long long ans=0;
			for (int i=1;i<=q;++i){
				long long k=rd(seed)%km;
				ans^=1LL*i*res[k];
			}
			printf("%lld\n",ans);
		}else{
			getres(64,n,x);
			int defres=0;
			for (int i=1;i<=n;++i) defres=add(defres,mul(a[i],getinv(n)));
			long long ans=0;
			for (int i=1;i<=q;++i){
				long long k=rd(seed)%km;
				if (k<=64) ans^=1LL*i*res[k];
				else ans^=1LL*i*defres;
			}
			printf("%lld\n",ans);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}