#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],c[N],B[N],s[N];
std::vector<int> bb[5025],b[5025];
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 ++) {
		int n, q, x;long long k_max;ll ans=0;int sum=0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		bb[0].resize(n+1),b[0].resize(n+1);
		for(int i=1;i<=n;++i)scanf("%d",&a[i]),add(sum,a[i]),bb[0][i]=a[i],b[0][i]=a[i],sub(b[0][i],a[i-1]);
		s[0]=0;for(int i=2;i<=n;++i)add(s[0],1LL*b[0][i]*(n-i+1)%mod);
		int p=0,lim=-1;
		for(int t=1;;++t){
			b[t].resize(n+1),bb[t].resize(n+1);
			for(int i=1;i<=n/2;++i)B[i]=bb[t-1][i],add(B[i],bb[t-1][n-i+1]);
			for(int i=1;i<=n;++i)b[t][i]=B[(i+1)/2],sub(b[t][i],B[i/2]);
			bb[t][1]=b[t][1];for(int i=2;i<=n;++i)bb[t][i]=bb[t][i-1],add(bb[t][i],b[t][i]);
			s[t]=0;for(int i=2;i<=n;++i)add(s[t],1LL*b[t][i]*(n-i+1)%mod);
			if(t>=22){
				lim=t;
				bool flag=1;for(int i=2;i<=n;++i)flag&=b[21][i]==b[t][i];
				if(flag){p=t-21;break;}
			}
		}
		ll inv=ksm(n);
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;int res;
			if(k<=lim)res=bb[k][x];
			else{
				ll tmp=(k-lim+p-1)/p*p,nk=k-tmp;
				ll d1=(1LL*sum*ksm(2,k)%mod+mod-s[nk])*inv%mod;
				res=((ll)bb[nk][x]-bb[nk][1]+d1+mod)%mod;
			}
			res=1LL*res*ksm(inv2,k)%mod,ans^=1LL*res*i;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
