#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int p=998244353;
const int inv2=(p+1)/2;

ll read(){static ll x;scanf("%lld",&x);return x;}
void write(ll x){printf("%lld",x);}
void print(ll x,char c='\n'){write(x),putchar(c);}

int power(int a,int b)
{
	int ret=1;
	for (;b;a=1LL*a*a%p,b/=2) if (b&1) ret=1LL*ret*a%p;
	return ret;
}
struct matrix
{
	int n,m;
	vector<vector<int>>a;
	matrix(){}
	matrix(int _n,int _m){n=_n,m=_m,a=vector<vector<int>>(n,vector<int>(m));}
	matrix(vector<int>b){n=1,m=b.size(),a=vector<vector<int>>(1,b);}
	friend matrix operator *(matrix a,matrix b)
	{
		matrix ret(a.n,b.m);
		for (int i=0;i<a.n;i++)
		for (int k=0;k<a.m;k++)
		for (int j=0;j<b.m;j++)
		ret.a[i][j]=(ret.a[i][j]+1LL*a.a[i][k]*b.a[k][j])%p;
		return ret;
	}
}tr[64];
int t,len,m;
vector<int>b[64];
void init(int n,vector<int>&a)
{
	t=0;
	for (int m=n<<1;m%2==0;m>>=1,t++)
	{
		b[t]=a;
//		for (int i:a) cerr<<i<<' ';cerr<<endl;
		vector<int>nxt(n/2);
		for (int i=0;i<n/2;i++) nxt[i]=(a[i]+a[n-1-i])%p;
		for (int i=0;i<n;i++) a[i]=nxt[i/2];
	}
//	cerr<<t<<endl;
	len=1;
	while (a[len-1]==a[len]&&a[n-len]==a[n-len-1]) len++;
	m=n/len;
//	cerr<<m<<endl;
	tr[0]=matrix(m,m);
	for (int i=0;i<m;i++) tr[0].a[i/2][i]++,tr[0].a[m-1-i/2][i]++;
	for (int i=1;i<=60;i++) tr[i]=tr[i-1]*tr[i-1];
}
int query(vector<int>&a,ll k,int x)
{
//	cerr<<k<<' '<<x<<':'<<b[k][x]<<endl;
	if (k<t) return b[k][x];
	k-=t;
	matrix ret(a);
	for (int i=0;k;k/=2,i++) if (k&1) ret=ret*tr[i];
	return ret.a[0][x/len];
}

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

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;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<int> a(n);
		for(int i = 0; i < n; i ++) {
			scanf("%d", &a[i]);
		}
		init(n,a);
		ll res=0;
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			int ans=1LL*query(a,k,x-1)*power(inv2,k)%p;
			res^=1LL*ans*i;
		}
		print(res);
	}
}
