#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;

const int N = 2e3 + 10, mod = 998244353;

template <typename T = int>
inline int read()
{
	T x = 0; char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while ( isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}

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

int a[N], b[N], c[N];

int main()
{
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	int test = read(), T = read(); u64 seed = read<u64>();
	for (int Case = 1; Case <= T; ++Case)
	{
		int n = read(), q = read(), x = read(); i64 k_max = read<i64>(); u64 ans = 0;
		for (int i = 1; i <= n; ++i) a[i] = read();
		for (int i = 1; i <= q; ++i)
		{
			i64 k = rd(seed) % k_max;
			for (int i = 1; i <= n; ++i) b[i] = a[i];
			while (k--)
			{
				for (int j = 1; j <= n / 2; ++j)
					c[j * 2] = c[j * 2 - 1] = 1LL * (b[j] + b[n - j + 1]) * (mod + 1) / 2 % mod;
				for (int j = 1; j <= n; ++j) b[j] = c[j];
			}
			ans ^= 1ULL * b[x] * i;
		}
		printf("%llu\n", ans);
	}
	return 0;
}