#include <bits/stdc++.h>
using namespace std;

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

const int N = 2e6 + 10;
const long long MOD = 998244353;
long long now[N], be[N];
int main() {
	freopen("noodle.in", "r", stdin);
	freopen("noodle.ans", "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 + 1);
		for(int i = 1; i <= n; i ++) {
			scanf("%d", &a[i]);
		}
		long long ans = 0;
		for(int i = 1; i <= q; i ++)
		{
			long long k = rd(seed) % k_max;
			for (int i = 1; i <= n; ++ i) now[i] = a[i];
			while(k --)
			{
				for (int i = 1; i <= n / 2; ++ i) now[i] = (now[i] + now[n - i + 1]) % MOD;
				for (int i = n; i; -- i) now[i] = now[(i + 1) >> 1] * ((MOD + 1) >> 1) % MOD;
			}
			ans ^= now[x] * i;
		}
		cout << ans << "\n";
	}
}
