#include <bits/stdc++.h>
#define rep(x, l, r) for(int x = l; x <= r; x++)
using namespace std;

const int mod = 998244353;
const int MAXM = 505;
const int MAXN = 2e6 + 5;
int n, a[MAXN], b[MAXN], c[MAXN];
int s[MAXM];

int fast_power(int a, int b){
	int x;
	for(x = 1; b; b >>= 1){
		if(b & 1) x = 1ll * x * a % mod;
		a = 1ll * a * a % mod;
	}
	return x;
}

const int h = fast_power(2, mod - 2);

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


int dfs(int x, int t, int s){
	if(!t) return 1ll * a[x] * s % mod;
	int ns = 1ll * s * h % mod;
	return dfs((x + 1) / 2, t - 1, ns) + dfs(n - (x + 1) / 2, t - 1, ns);
}

int main() {
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	int test, T;
	unsigned long long seed;
	scanf("%d%d%llu", &test, &T, &seed);
	while(T--){
		int q, x;
		long long k_max;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		int sum = 0;
		rep(i, 1, n){
			scanf("%d", &a[i]);
			sum = (sum + a[i]) % mod;
		}
		if(n <= 500 && k_max <= 500){
			s[0] = a[x];
			rep(i, 1, k_max){
				rep(j, 1, n / 2){
					b[j] = a[j] + a[n - j + 1];
					c[j * 2 - 1] = c[j * 2] = 1ll * b[j] * h % mod;
				}
				rep(j, 1, n) a[j] = c[j];
				s[i] = a[x];
			}
			long long ans = 0;
			rep(i, 1, q){
				long long k = rd(seed) % k_max;
				ans = ans ^ (1ll * s[k] * i);
			}
			printf("%lld\n", ans);
		}
		else if(k_max <= 10){
			s[0] = a[x];
			rep(i, 1, k_max) s[i] = dfs(x, i, 1);
			long long ans = 0;
			rep(i, 1, q){
				long long k = rd(seed) % k_max;
				ans = ans ^ (1ll * s[k] * i);
			}
			printf("%lld\n", ans);
		}
		else{
			int res = 1ll * sum * fast_power(n, mod - 2) % mod;
			long long ans = 0;
			rep(i, 1, q){
				long long k = rd(seed) % k_max;
				if((1 << k) == n) ans = ans ^ (1ll * res * i);
			}
			printf("%lld\n", ans);
		}
	}
}
