#include<bits/stdc++.h>
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
const int N=2000005,mod=998244353,inv2=(mod+1)/2;typedef long long ll;
template<typename _Tp1,typename _Tp2>inline void add(_Tp1 &a,_Tp2 b){a=a+b>=mod?a+b-mod:a+b;}
template<typename _Tp1,typename _Tp2>inline void sub(_Tp1 &a,_Tp2 b){a=a<b?a+mod-b:a-b;}
ll ksm(ll a,ll b=mod-2){ll res=1;while(b){if(b&1)res=res*a%mod;a=a*a%mod,b>>=1;}return res;}
int a[N],b[5005][10005],B[N];
int main(){
	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;ll ans=0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		int o=0;
		for(int i=1;i<=n;++i)scanf("%d",&a[i]),b[0][i]=a[i],add(o,a[i]);
		for(int t=1;t<=5000;++t){
			for(int i=1;i<=n/2;++i)B[i]=b[t-1][i],add(B[i],b[t-1][n-i+1]);
			for(int i=1;i<=n;++i)b[t][i]=B[(i+1)/2];
		}
		ll inv=ksm(n);
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;int res;
			res=b[k][x];
			res=1LL*res*ksm(inv2,k)%mod;
			ans^=1LL*res*i;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
