#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;
}

typedef unsigned long long ull;
typedef long long ll;

template <typename T>
inline void read(T &f) {
	f = 0; int fu = 0; char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fu = 1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		f = f * 10 + (c - '0');
		c = getchar();
	}
	if (fu) f = -f;
}

const int md = 998244353, inv2 = (md + 1) / 2;

inline int add(int x, int y) {
	if (x + y >= md) return x + y - md;
	return x + y;
}

inline int sub(int x, int y) {
	if (x < y) return x - y + md;
	return x - y;
}

inline int mul(int x, int y) { return 1ull * x * y % md; }

inline int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		y >>= 1; x = mul(x, x);
	}
	return ans;
}

inline int div2(int x) {
	if (x & 1) return (x + md) >> 1;
	return x >> 1;
}

const int N = 2000005;

ull seed;
int a[N], b[105][205];
int T, n, q, x; ll k_max;

int main() {
	freopen("noodle.in", "r", stdin);
	freopen("noodle.ans", "w", stdout);
	scanf("%d%d%llu", &T, &T, &seed);
	while (T--) {
//		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		read(n); read(q); read(x); read(k_max);
		for (int i = 1; i <= n; i++) read(a[i]), b[0][i] = a[i];
		for (int i = 1; i <= k_max; i++) {
			for (int j = 1; j <= n / 2; j++) {
				int x = div2(add(b[i - 1][j], b[i - 1][n - j + 1]));
				b[i][j * 2 - 1] = b[i][j * 2] = x;
			}
		}
		ll ans = 0;
		for (int i = 1; i <= q; i++) {
			long long k = rd(seed) % k_max;
			ans ^= 1ll * i * b[k][x];
		}
		printf("%lld\n", ans);
	}
}
