#include <bits/stdc++.h>
#define Mod 998244353
#define hlf 499122177
#define ll long long
#define ull unsigned long long
using namespace std;

ull rd(ull &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; ull seed;
	scanf("%d%d%llu", &test, &T, &seed);
	while (T--) {
		int n, q, x; long long k_max, ans = 0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<int> a(n + 1), b(n + 1), c(n + 1);
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= q; i++) {
			ll k = rd(seed) % k_max;
			for (int j = 1; j <= n; j++) c[j] = b[j] = a[j];
			for (int j = 1; j <= k; j++) {
				for (int K = 1; K <= n; K++) {
					int x = (K + 1) / 2;
					b[K] = 1ll * (c[x] + c[n+1-x]) * hlf % Mod;
				}
				for (int K = 1; K <= n; K++) c[K] = b[K];
			}
			ans ^= (1ll * i * c[x]);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
