#include <bits/stdc++.h>
const int P=998244353;
using namespace std;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}

int pwr(int a,int b,int mod){
	int w=a,ret=1;
	for(int k=b;k;k>>=1){if(k&1)ret=(long long)ret*w%mod;w=(long long)w*w%mod;}
	return ret;
}

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, sum=0, NowAns;
		long long k_max, Ans=0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<int>a(n + 1),F(n << 1 | 1);F[0]=-1;
		for(int i = 1; i <= n; i ++){
			scanf("%d", &a[i]);
			sum=(sum + a[i])%P;
			F[i] = F[i+n] = -1;
		}
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			if(!k) NowAns=a[x];else{
				int q=pwr(2,k,n<<1),p=(long long)(pwr(2,k,P)-q+P)%P*pwr(n<<1,P-2,P)%P;//2^k=p*2n+q.
				NowAns=(long long)2*p%P*sum%P;
				if(F[q]<0){
					F[q]=0;
					for(int j=1;(j<<1)<=n;j++){
						#define pos_1 (       x  )
						#define pos_2 ((n<<1)-x+1)
						int l=((long long)(j-1)*q+1)%(n<<1),r=(long long)j*q%(n<<1);
						if(l<=r&&l<=pos_1&&pos_1<=r||l>r&&(l<=pos_1||pos_1<=r))F[q]=(F[q]+(a[j]+a[n-j+1])%P)%P;
						if(l<=r&&l<=pos_2&&pos_2<=r||l>r&&(l<=pos_2||pos_2<=r))F[q]=(F[q]+(a[j]+a[n-j+1])%P)%P;
						#undef pos_1
						#undef pos_2
					}
				}
				NowAns=(NowAns+F[q])%P;
				NowAns=(long long)NowAns*pwr(pwr(2,P-2,P),k,P)%P;
			}
			Ans^=(long long)NowAns*i;
		}
		printf("%lld\n",Ans);
	}
	return 0;
}