#include <bits/stdc++.h>
using namespace std;
#define Mod 998244353
typedef long long ll;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
int b[2000005],n,x,k;
int f[25][2000005];
struct Matrix{
	int n,m;
	int a[105][105];
}d,r;
inline Matrix operator * (Matrix x, Matrix y)
{
	Matrix res;
	res.m = x.m,res.n = y.n;
	for(int i = 1;i <= res.n;i++)
		for(int j = 1;j <= res.m;j++) 
			res.a[i][j] = 0;
	for(int i = 1;i <= res.n;i++)
	{
		for(int j = 1;j <= res.m;j++)
		{
			//cout<<i<<' '<<j<<endl;
			for(int k = 1;k <= x.n;k++)
			{
				res.a[i][j] = (res.a[i][j] + 1ll*x.a[k][j]*y.a[i][k])%Mod;
				//cout<<x.a[k][j]<<' '<<y.a[i][k]<<endl;
			}
		}
	}
	return res;
}
Matrix qpow(Matrix x,ll t)
{
	Matrix res;
	res.n = n,res.m = n;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++) 
			res.a[i][j] = 0;
	for(int i = 1;i <= n;i++) res.a[i][i] = 1;
	while(t)
	{
		if(t&1) res = res*x;
		x = x*x;
		t /= 2;
	}
	return res;
}
ll solve1()
{
	r.n = n;r.m = 1;
	for(int i = 1;i <= n;i++) r.a[i][1] = b[i];
	Matrix M = r*qpow(d,k);
	return M.a[x][1];
}
ll solve2()
{
	if(k <= 22) return f[k][x];
	else return f[22][x];
}
ll solve3()
{
	if(k <= 22)
	{
		return f[k][x];
	}
	else
	{
		Matrix r,rr;
		r.n = 2;
		r.m = 1;
		r.a[1][1] = f[22][1];
		r.a[2][1] = f[22][n];
		rr.m = rr.n = 2;
		rr.a[1][2] = (Mod+1)/2;
		rr.a[1][1] = (Mod+1)/2;
		rr.a[2][1] = 1;
		rr.a[2][2] = 0;
		r = r * qpow(rr,k-22);
		return (x<=65536)?r.a[1][1]:r.a[2][1];
	}
}
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 q;
		long long k_max;
		ll ans = 0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		d.n = d.m = n;
		for(int i = 1; i <= n; i ++) {
			scanf("%d", &b[i]);
		}
		if(test <= 9 && test != 2 && test != 3 && test != 7)
		{
			for(int i = 1;i <= n;i++)
				for(int j = 1;j <= n;j++)
					d.a[i][j] = 0;
			for(int i = 1;i <= n/2;i++) d.a[i*2][n-i+1] = (Mod+1)/2,d.a[i*2-1][n-i+1] = (Mod+1)/2;
			for(int i = 1;i <= n/2;i++) d.a[i*2][i] = (Mod+1)/2,d.a[i*2-1][i] = (Mod+1)/2;
		}
		if(test == 2 || test == 3)
		{
			for(int i = 1;i <= n;i++) f[0][i] = b[i];
			for(int j = 1;j <= 22;j++)
			{
				for(int i = 1;i <= n;i++)
				{
					int k = (i+1)/2;
					f[j][i] = (1ll*(f[j-1][k] + f[j-1][n+1-k])*(Mod+1)/2)%Mod;
				}
			}
		}
		for(int i = 1; i <= q; i ++) {
			k = rd(seed) % k_max;
			if(test <= 9 && test != 2 && test != 3 && test != 7) ans ^= i*solve1();
			if(test == 2 || test == 3) ans ^= i*solve2();// k <= 10 n = 2^x
			if(test == 7) ans ^= i*solve3();
		}
		printf("%lld\n",ans);
	}
	return 0;
}
