#include <bits/stdc++.h>
using namespace std;
#define md 998244353
#define int long long
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
int read()
{
	int x=0;bool f=0;char c=getchar();
	for(;!isdigit(c);c=getchar())f^=!(c-45);
	for(;isdigit(c);c=getchar())x=x*10+c-48;
	if(f)x=-x;return x;
}
int ans[505],a[2000500];
int lg2(int x)
{
	return 63-__builtin_clzll(x);
}
signed main() {
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	int test, T;
	unsigned long long seed;
	cin>>test>>T>>seed;
	for(int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max;
		n=read(),q=read(),x=read(),k_max=read();
		for(int i = 1; i <= n; i ++) {
			a[i]=read();
		}
		ans[0]=a[x];
		if(k_max<=500)
		{
			for(int j=1;j<=k_max;j++)
			{
				for(int i=1;i<=n/2;i++)a[i]=(a[i]+a[n-i+1])%md;
				for(int i=n;i>=1;i--)a[i]=a[(i+1)/2]*((md+1)/2)%md;
				ans[j]=a[x];
			}
			int res=0;
			for(int i = 1; i <= q; i ++) {
				long long k = rd(seed) % k_max;
				res^=(ans[k]*i);
			}
			cout<<res<<"\n";
			continue;
		}
		int kc=lg2(n);
		for(int j=1;j<=kc;j++)
		{
			for(int i=1;i<=n/2;i++)a[i]=(a[i]+a[n-i+1])%md;
			for(int i=n;i>=1;i--)a[i]=a[(i+1)/2]*((md+1)/2)%md;
			ans[j]=a[x];
		}
		if(n==1ll<<kc)
		{
			int kc=lg2(n);
			for(int j=1;j<=kc;j++)
			{
				for(int i=1;i<=n/2;i++)a[i]=(a[i]+a[n-i+1])%md;
				for(int i=n;i>=1;i--)a[i]=a[(i+1)/2]*((md+1)/2)%md;
				ans[j]=a[x];
			}
			int res=0;
			for(int i = 1; i <= q; i ++) {
				long long k = rd(seed) % k_max;
				res^=((k>=kc?ans[kc]:ans[k])*i);
			}
			cout<<res<<"\n";
			continue;
		}
		
		for(int j=1;j<=kc;j++)
		{
			for(int i=1;i<=n/2;i++)a[i]=(a[i]+a[n-i+1])%md;
			for(int i=n;i>=1;i--)a[i]=a[(i+1)/2]*((md+1)/2)%md;
			ans[j]=a[x];
		}
		int res=0;
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			int re=k%kc;
			if(re==0)re==kc;
		}
		cout<<res<<"\n";
	}
}
