#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;

void ckmax(int &a,int b){a=(a>b?a:b);}
void ckmin(int &a,int b){a=(a<b?a:b);}

int read()
{
	int f=1,num=0;char ch=getchar();
	while(!((ch<='9'&&ch>='0')||ch=='-'))ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=num*10+ch-'0',ch=getchar();
	return num*f;
}

const int Mod=998244353;
const int inv2=499122177;

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

const int M=510;
struct matrix
{
	vector<vector<int> >a;
	int n,m;
}base[70],res;

matrix operator * (matrix a,matrix b)
{
	matrix c;
	c.n=a.n,c.m=b.m;
	c.a.resize(c.n+1);
	for (int i=1;i<=c.n;i++)c.a[i].resize(c.m+1);
//	c.clear();
//	cout<<c.n<<' '<<c.m<<'\n';
	for (int i=1;i<=c.n;i++)for (int j=1;j<=c.m;j++)c.a[i][j]=0;
	for (int i=1;i<=c.n;i++)
		for (int k=1;k<=c.m;k++)
			for (int j=1;j<=c.m;j++)
				c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%Mod;
	return c;
}

signed main()
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
//	freopen("noodle_ex2.in","r",stdin);
//	freopen("qwq.txt","r",stdin);
	int test, T;
	unsigned long long seed;
	scanf("%lld%lld%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max;
		scanf("%lld%lld%lld%lld", &n, &q, &x, &k_max);
		vector<int> a(n + 1);
		for(int i = 1; i <= n; i ++) {
			scanf("%lld", &a[i]);
		}
		if (k_max<=500||__builtin_popcount(n)==1)
		{
			int K=k_max;
			if (__builtin_popcount(n)==1)ckmin(K,25ll);
			vector<int> ans(K+1);
			ans[0]=a[x];
			for (int w=1;w<=K;w++)
			{
				vector<int> b(n+1);
				for (int i=1;i<=n;i++)b[i]=(a[(i+1)/2]+a[n-(i+1)/2+1])*inv2%Mod;
				a=b;ans[w]=a[x];
			}int res=0;
			for (int i=1;i<=q;i++)
			{
				int k=rd(seed)%k_max;
				ckmin(k,K);
				res^=ans[k]*i;
			}
			cout<<res<<'\n';
			continue;
		}//test 1 2 3 7,20 pts
		if (n<=500)
		{
			base[0].a.clear();base[0].n=base[0].m=n;
			base[0].a.resize(n+1);
			for (int i=1;i<=n;i++)base[0].a[i].resize(n+1);
			for (int i=1;i<=n;i++)base[0].a[(i+1)/2][i]=base[0].a[n-(i+1)/2+1][i]=inv2;
			for (int i=1;i<=60;i++)base[i]=base[i-1]*base[i-1];
			int ans=0;
			for (int i=1;i<=q;i++)
			{
				int k=rd(seed)%k_max;
				res.a.clear();res.n=1,res.m=n;
				res.a.resize(2),res.a[1].resize(n+1);
				for (int j=1;j<=n;j++)res.a[1][j]=a[j];
				for (int j=60;j>=0;j--)
					if ((k>>j)&1)res=res*base[j];
				ans^=res.a[1][x]*i;
			}
			cout<<ans<<'\n';
			continue;
		}
//		for(int i = 1; i <= q; i ++) {
//			long long k = rd(seed) % k_max;
//			
//		}
	}
	return 0;
}
