#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
enum{N=4000007,M=607,P=998244353,Q=P/2+1};
int n,q,x,e,A[N],B[N],C[N],F[N],X[N],R[M];
typedef int Ma[M][M];
Ma G[63];
unsigned long long seed;
LL k_max;
int Pow(int x,int k=P-2) {
	int r=1;
	while(k) {
		if(k&1) r=1LL*r*x%P;
		x=1LL*x*x%P,k>>=1;
	}
	return r;
}
void Sqr(Ma A,Ma B) {
	For(k,1,e) For(i,1,e) if(A[i][k]) {
		For(j,1,e) B[i][j]=(B[i][j]+1LL*A[i][k]*A[k][j])%P;
	}
}
void Mul(Ma A,int *B) {
	For(i,1,e) C[i]=0;
	For(k,1,e) if(B[k])
		For(i,1,e)
		C[i]=(C[i]+1LL*A[i][k]*B[k])%P;
	For(i,1,e) B[i]=C[i];
}
void magic() {
	int I=5000,Z=20,W=4980;
	F[0]=A[x];
	if(!(n&(n-1))) k_max=log2(n)+1;
	if(k_max<I) I=k_max;
	For(i,1,I) {
		For(i,1,n/2) B[i]=A[i]+A[n-i+1],B[i]>=P&&(B[i]-=P),(B[i]&1)&&(B[i]+=P),B[i]>>=1;
		For(i,1,n/2) A[i*2-1]=A[i*2]=B[i];
		F[i]=A[x];
	}
	if(k_max==I) {
		LL ans=0;
		For(i,1,q) {
			LL k=rd(seed)%k_max;
			ans^=1LL*F[min(k,(LL)I)]*i;
		}
		printf("%lld\n",ans);
		return;
	}
	int a=0,b=0,f=0,d=0;
	For(u,1,W) {
		X[u]=F[u+Z];
		int x=P-X[u];
		For(i,1,a) x=(x+1LL*X[u-i]*A[i])%P;
		if(!x) continue;
		if(!a) {
			d=x,a=f=u;
			continue;
		}
		int k=1LL*x*Pow(P-d)%P,c=0;
		For(i,1,u-f-1) C[++c]=0;
		C[++c]=P-k;
		For(i,1,b) C[++c]=1LL*B[i]*k%P;
		while(c<a) C[++c]=0;
		For(i,1,a) (C[i]+=A[i])%=P;
		if(a<=u-f+b) {
			b=a,f=u,d=x;
			For(i,1,a) B[i]=A[i];
		}
		a=c;
		For(i,1,a) A[i]=C[i];
	}
	int t=log2(k_max);
	e=a+1;
	For(i,0,t) For(j,0,e) For(k,0,e) G[i][j][k]=0;
	For(i,1,a) G[0][a+1][i]=A[i],G[0][i][i+1]=1;
	For(i,1,t) Sqr(G[i-1],G[i]);
	LL ans=0;
	For(i,1,q) {
		LL k=rd(seed)%k_max;
		if(k<=I) {
			ans^=1LL*F[k]*i;
			continue;
		}
		For(i,1,e) R[i]=F[i];
		For(i,0,t) if((k-1)&1LL<<i) Mul(G[i],R);
		ans^=1LL*R[1]*i;
	}
	printf("%lld\n",ans);
}
int main() {
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	int test, T;
	scanf("%d%d%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) {
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		for(int i = 1; i <= n; i ++) {
			scanf("%d", &A[i]);
		}
		magic();
	}
	return 0;
}
