#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for(int i = l, i##end = r; i <= i##end; ++ i)
#define per(i, l, r) for(int i = l, i##end = r; i >= i##end; -- i)
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e6 + 15, P = 998244353;

template <class T>
inline T read() {
	T res = 0; char ch = getchar(); bool f = 1;
	for(; ch < '0' || ch > '9'; ch = getchar())
		if(ch == '-') f = 0;
	for(; ch >= '0' && ch <= '9'; ch = getchar())
		res = res * 10 + ch - '0';
	return f ? res : -res;
}
#define rdi read <int>

const ll i2 = (P + 1) / 2;

int Tid, n, q, x;
ull seed;
ll lans[N];
ll ans, kmax, k, lim;
ll a[N], b[N];

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

void init() {
	lans[0] = a[x];
	rep(t, 1, lim) {
		rep(i, 1, n / 2) b[i * 2 - 1] = b[i * 2] = (a[n - i + 1] + a[i]) * i2 % P;
		lans[t] = b[x];
		memcpy(a, b, 8 * (n + 3));
	}
}

void solve() {
	n = rdi(); q = rdi(); x = rdi();
	kmax = read <ll> ();
	rep(i, 1, n) a[i] = rdi();
	if(kmax * n <= 2e7 + 15) lim = kmax;
	else for(int tmp = n & -n; (1ll << lim) <= tmp; ++ lim) ;
	ans = 0;
	init();
	rep(t, 1, q) {
		k = rd(seed) % kmax;
		ans ^= lans[min(k, lim)] * t;
	}
	printf("%lld\n", ans);
}

int main() {
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	int T;
	Tid = rdi(); T = rdi();
	seed = read <ull> ();
	while(T --) solve();
	return 0;
}