#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define N 2000
#define Mod 998244353
#define For(i,x,y)for(i=x;i<=(y);i++)
struct matrix
{
	int g[N][N];
}p,q;
int a[2000005],val[30],n;
ull rd(ull&x)
{
	x^=x<<13;
	x^=x>>7;
	x^=x<<17;
	return x;
}
matrix mul(matrix p,matrix q)
{
	matrix d;
	int i,j,k;
	For(i,1,n)
	For(j,1,n)
	{
		d.g[i][j]=0;
		For(k,1,n)d.g[i][j]=(d.g[i][j]+1LL*p.g[i][k]*q.g[k][j])%Mod;
	}
	return d;
}
int ksm(int x,int y)
{
	return(!y?1:1LL*ksm(1LL*x*x%Mod,y>>1)*(y&1?x:1)%Mod);
}
int main()
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	ull seed;
	ll k_max,k,ans;
	int test,T,qq,x,i,inv2,h,l,r,id;
	scanf("%d%d%llu",&test,&T,&seed);
	while(T--)
	{
		scanf("%d%d%d%lld",&n,&qq,&x,&k_max);
		For(i,1,n)scanf("%d",&a[i]);
		val[0]=a[x];
		ans=h=0;
		inv2=ksm(2,Mod-2);
		while(!(n&1))
		{
			h++;
			For(i,1,n>>1)a[i]=1LL*(a[i]+a[n-i+1])*inv2%Mod;
			n>>=1;
			val[h]=a[(x>>h)+(x%(1<<h)>0)];
		}
		l=1;
		r=n;
		For(i,1,n)
		{
			q.g[l][i]=q.g[r][i]=inv2;
			if(!(i&1))l++,r--;
		}
		For(id,1,qq)
		{
			k=rd(seed)%k_max;
			if(k<=h)
			{
				ans^=1LL*val[k]*id;
				continue;
			}
			else
			{
				k-=h;
				For(i,1,n)p.g[1][i]=a[i];
				while(k)
				{
					if(k&1)p=mul(p,q);
					k>>=1;
					q=mul(q,q);
				}
				ans^=1LL*p.g[1][(x>>h)+(x%(1<<h)>0)]*id;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
