#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
	int sum = 0, nega = 1; char ch = getchar();
	while(ch > '9' || ch < '0') {if(ch == '-') nega = -1; ch = getchar();}
	while(ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
const int N = 2e6 + 9, mod = 998244353;
int n, test, T, Q, xp, kmax, cnt1, cnt2, inv_2;
int b[N], c[N], Base, a[N];
unsigned long long seed;
vector<int> G[N], P[N];
inline int Pow(int x, int y)
{
	int res = 1, base = x;
	while(y)
	{
		if(y & 1) res = res * base % mod;
		base = base * base % mod;
		y >>= 1;
	}
	return res;
}
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
inline void init()
{
	int tt = n, sum = 0;
	for (int i = 1; i <= n; i++) sum = (sum + a[i]) % mod, b[i] = a[i];
	while(tt % 2 == 0)
	{
		for (int i = 1; i <= n; i++) 
		{
			int t = (i + 1) / 2;
			c[i] = (b[t] + b[n + 1 - t]) % mod; 
		}
		for (int i = 1; i <= n; i++) b[i] = c[i];
		cnt1++;
		for (int i = 1; i <= n; i++) G[cnt1].push_back(b[i]);
		tt /= 2;
		sum = sum * 2 % mod;
	}
	tt *= 2; Base = n / tt;
	for (int i = 1; i <= tt; i++) b[i] = b[i * Base];
//	for (int i = 1; i <= tt; i++) cout << b[i] << endl;
	for (int i = 1; i <= tt; i++) b[i] = (n * b[i] - sum + mod) % mod;
//	for (int i = 1; i <= tt; i++) cout << b[i] << endl;
	for (int i = 1; i <= (tt - 2) / 2; i++) 
	{
		for (int j = 1; j <= tt; j++) P[cnt2].push_back(b[j]);
		cnt2++;
		sum = sum * 2 % mod;
		for (int j = 1; j <= tt; j++) 
		{
			int t = (j + 1) / 2;
			c[j] = (b[t] + b[tt + 1 - t]) % mod; 
		}
		for (int j = 1; j <= tt; j++) b[j] = c[j];
	}
	//cout << cnt2 << "fuck" << endl;
	return ;
}
inline void solve()
{
	n = read(); Q = read(), xp = read(), kmax = read(); cnt1 = cnt2 = 0;
	int awa = 0;
	int pep = 0;
//	cout << n << endl;
	for (int i = 1; i <= n; i++) a[i] = read(), pep = (pep + a[i]) % mod;
	init();
//	if(n == 6) for (int i = 0; i < 6; i++) cout << P[1][i] << "qwq" << endl;
	for (int i = 1; i <= Q; i++)
	{
		long long k = rd(seed) % kmax;
		//cout << k << "qwq" << endl;
		if(k == 0) awa ^= a[xp] * i;
		else if(k <= cnt1) awa ^= (G[k][xp - 1] * Pow(inv_2, k) % mod) * i;
		else if(cnt2 == 0) awa ^= (G[cnt1][xp - 1] * Pow(inv_2, k) % mod) * i;
		else 
		{
			int xxp = (xp + Base - 1) / Base;
			awa ^= (((P[(k - cnt1) % cnt2][xxp - 1] + pep * Pow(2, k) % mod) * Pow(n, mod - 2) % mod * Pow(inv_2, k) % mod) * i);
		}
	}
	printf("%lld\n", awa);
	for (int i = 1; i <= cnt1; i++) G[i].clear();
	for (int i = 0; i < cnt2; i++) P[i].clear();
}
signed main()
{
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	inv_2 = Pow(2, mod - 2);
	test = read(), T = read(), seed = read();
	for (int ttt = 1; ttt <= T; ttt++) solve();
	return 0;
}
