#include <bits/stdc++.h>
#define int long long
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

using namespace std;

int read() {
	int x=0, f=0; char c=getchar();
	while (!isdigit(c)) f|=c=='-', c=getchar();
	while (isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
	return f ? -x : x;
}

const int N=555, p=998244353, inv2=(p+1)/2;
int a[N], b[N], ans[N];

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}

signed main() {
	fre(noodle);
	int test=read(), T=read();
	unsigned long long seed; scanf("%llu", &seed);
	while (T--) {
		int n=read(), q=read(), x=read(), k_max=read();
		for (int i=1; i<=n; i++) a[i]=read(); ans[0]=a[x];
		for (int i=1; i<=500; i++) {
			for (int i=1; i<=n/2; i++) b[i]=(a[i]+a[n-i+1])%p;
			for (int i=1; i<=n; i++) a[i]=b[(i+1)/2]*inv2%p;
			ans[i]=a[x];
		}
		int res=0;
		for (int i=1; i<=q; i++) res^=i*ans[rd(seed)%k_max];
		printf("%lld\n", res);
	}
	return 0;
}

/*nwysbwwq
#include <bits/stdc++.h>
#define int long long
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

using namespace std;

int read() {
	int x=0, f=0; char c=getchar();
	while (!isdigit(c)) f|=c=='-', c=getchar();
	while (isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
	return f ? -x : x;
}

const int N=2e6+10, p=998244353, inv2=(p+1)/2, L=63;
int n, q, x, k_max, tt, t, sum, a[N], b[N], tot[L*2], ans[L*2], A[L], B[L], d[L];

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}

void init(int flag, int *tot) {
	for (int j=1; j<=tt+t; j++) {
		for (int i=1; i<=n/2; i++) b[i]=(a[i]+a[n-i+1])%p;
		for (int i=1; i<=n; i++) a[i]=b[(i+1)/2];
		tot[j]=a[x];
		if (flag && j>tt) d[j-1-tt]=(tot[j]-tot[j-1]*2+p+p)%p;
	}
}

int count(int x) {
	int res=0;
	while (x) {
		res++;
		x-=x&-x;
	}
	return res;
}

struct matrix {
	int a[2][2];
	void clear() {
		a[0][0]=a[0][1]=a[1][0]=a[1][1]=0;
	}
	void init(int q, int w, int e, int r) {
		a[0][0]=q, a[0][1]=w, a[1][0]=e, a[1][1]=r;
	}
};

matrix mul(matrix a, matrix b) {
	matrix c; c.clear();
	for (int i=0; i<2; i++)
		for (int k=0; k<2; k++)
			for (int j=0; j<2; j++)
				c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%p;
	return c;
}

int calc(int u) {
	int a=A[(u-tt)%t], b=B[(u-tt)%t];
	int 
	matrix x, r; x.init(0, A[t], 1, B[t]), r.init(1, 0, 0, 1);
	int K=(u-tt)/t;
	while (K) {
		if (K&1) r=mul(r, x);
		x=mul(x, x); K>>=1;
	}
//	printf("#%lld#%lld\n#%lld#%lld\n", r.a[0][0], r.a[0][1], r.a[1][0], r.a[1][1]);
//	printf("%lld++%lld\n", tot[tt], tot[tt]*A[t]+B[t]);
//	printf("-------%lld\n", (r.a[0][0]*tot[tt]+r.a[1][0]*((tot[tt]*A[t]+B[t])%p))%p);
//	return (r.a[0][0]*tot[tt]+r.a[1][0]*((tot[tt]*A[t]+B[t])%p))%p*a+b%p;
//	return (A[(u-tt)%t]*r.a[1][0]+B[(u-tt)%t])%p;
}

int power(int x, int y) {
	int r=1;
	while (y) {
		if (y&1) r=r*x%p;
		x=x*x%p; y>>=1;
	}
	return r;
}

signed main() {
//	fre(noodle);
	int test=read(), T=read();
	unsigned long long seed; scanf("%llu", &seed);
	while (T--) {
		n=read(), q=read(), x=read(), k_max=read(), tt, t=count(n), sum=0;
		if (n==(n&-n)) tt=(int)log2(n)+1; else tt=(int)log2(n)+3;
		for (int i=1; i<=n; i++) a[i]=0; a[1]=1; init(1, tot);
		for(int i=1; i<=n; i++) a[i]=read(), sum+=a[i]; ans[0]=a[x]; init(0, ans);
		A[0]=1, B[0]=0;
		for (int i=1; i<=t; i++) {
			A[i]=A[i-1]*2%p;
			B[i]=(B[i-1]*2+d[i-1])%p;
		}
		for (int i=1; i<=60; i++) {
			AA[i]=
		}
		printf("%lld\n", tt);
		for (int i=1; i<=q; i++) {
//			int k=rd(seed)%k_max;
int k=read();
			printf("k=%lld\n", k);
			if (k<=tt+t) printf("%lld\n", ans[k]*power(power(2, k), p-2)%p);
			else {
				int w=(k-tt)%t+tt;
				printf("%lld\n", (sum*(calc(k)-tot[w])+ans[w])%p*power(power(2, k), p-2)%p);
			}
		}
	}
	return 0;
}
*/

/*
1 1 1
14 0 5 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14
==========================
1 1 0
6 10 2 0
1 2 3 4 5 6
6
7
8
9

*/
