#include <bits/stdc++.h>
using namespace std;

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
const int N=2e6+10,mod=998244353;
int b[N],a[N];
int mul(int a,int b){int res=1;while(b){if(b&1) res=1ll*res*a%mod;a=1ll*a*a%mod;b>>=1;}return res;}
int main()
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	int test,T;
	unsigned long long seed;
	scanf("%d%d%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max,res=0,sum=0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		for(int i = 1; i <= n; i ++) scanf("%d", &a[i]),sum=(sum+a[i])%mod;b[0]=a[x];
		for(int j=1;j<=min(k_max,500ll);j++)
		{
			for(int i=1;i<=n/2;i++) a[i]=1ll*(a[i]+a[n-i+1])%mod*mul(2,mod-2)%mod;
			for(int i=n/2;i>=1;i--) a[i*2-1]=a[i];
			for(int i=1;i<n;i+=2) a[i+1]=a[i];
			b[j]=a[x];
		}
		for(int i = 1; i <= q; i ++)
		{
			long long k = rd(seed) % k_max,ans=0;
			if(k<=500) ans=b[k];
			else if((1<<((int)log2(n)))==n)
			{
				int k=log2(n);
				ans=1ll*mul(2,n-k)*mul(mul(2,k),mod-2)%mod;
			}
			else ans=114514;
			res=(res^(1ll*i*ans));
		}
		printf("%lld\n",res);
	}
}