#include<bits/stdc++.h>
// #define int long long
#define mod 998244353
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define per(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
int read()
{
	int w=1,x=0;char c=getchar();
	while(!isdigit(c)){if(c=='-')w=-1;c=getchar();}
	while(isdigit(c))x=x*10+(c-'0'),c=getchar();
	return w*x;
}
void read(int &x){x=read();}
void write(int x)
{
	if(x<0){x=-x;putchar('-');}
	if(x/10)write(x/10);
	putchar(x%10+'0');
}
void write(int x,char c){write(x),putchar(c);}

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

int qpow(long long a,long long b)
{
	a%=mod;int ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ans;
}
long long inv2=qpow(2,mod-2);
int a[505],b[505],c[505];
int main()
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	int test,T;
	scanf("%d%d%llu",&test,&T,&seed);
	while(T--)
	{
		int n,q,x;
		long long k_max,ans=0;
		scanf("%d%d%d%lld",&n,&q,&x,&k_max);
		rep(i,1,n)read(a[i]);
		
		rep(i,1,q)
		{
			long long k=rd(seed)%k_max;
			rep(i,1,n)b[i]=a[i];
			rep(j,1,k)
			{
				// rep(i,1,n)write(b[i]," \n"[i==n]);
				rep(i,1,n)c[i]=b[i]+b[n-i+1];
				// rep(i,1,n)write(c[i]," \n"[i==n]);
				rep(i,1,n)b[i]=c[(i+1)/2]*inv2%mod;
			}
			// rep(i,1,n)write(b[i]," \n"[i==n]);
			ans^=b[x]*i;
		}
		cout<<ans<<'\n';
	}
}
/*


*/