#include <bits/stdc++.h>

using namespace std;
#define P 998244353
#define INV2 499122177LL

int test, T, n, q, x, a[2000001];
unsigned long long seed;
long long k_max;

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

namespace sub1 {

int ans[500], b[1000001];
long long xorsum;

void main() {
	for (int Case = 1; Case <= T; ++Case) {
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
		ans[0] = a[x];
		for (int i = 1; i < k_max; ++i) {
			for (int j = 1; j <= n / 2; ++j)
				b[j] = (a[j] + a[n - j + 1]) * INV2 % P;
			for (int j = 2; j <= n; j += 2) a[j - 1] = a[j] = b[j / 2];
			ans[i] = a[x];
		}
		xorsum = 0;
		for (int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			xorsum ^= (long long)ans[k] * i;
		}
		printf("%lld\n", xorsum);
	}
}

}

namespace sub2 {

pair<long long, int> k[2000001];
long long xorsum;

void main() {
	for (int Case = 1; Case <= T; ++Case) {
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
		for (int i = 1; i <= q; ++i) {
			k[i].first = rd(seed) % k_max;
			k[i].second = i;
		}
		sort(k + 1, k + q + 1);
		xorsum = 0;
		
		int ptr_k = 1, step = 0;
		while (n % 2 == 0) {
			while (ptr_k <= q && k[ptr_k].first == step) {
				xorsum ^= (long long)a[x] * k[ptr_k].second;
				++ptr_k;
			}
			for (int i = 1; i <= n / 2; ++i)
				a[i] = (a[i] + a[n - i + 1]) * INV2 % P;
			n /= 2;
			x = (x + 1) / 2;
			++step;
		}
		while (ptr_k <= q && k[ptr_k].first == step) {
			xorsum ^= (long long)a[x] * k[ptr_k].second;
			++ptr_k;
		}
		for (int i = 1; i <= n / 2; ++i)
			a[i] = (a[i] + a[n - i + 1]) * INV2 % P;
		x = (x + 1) / 2;
		++step;
		
		int m = (n + 1) / 2;
		long long trans[60][m + 1][m + 1], mul[m + 1], tmp[m + 1], cur;
		memset(trans, 0, sizeof(trans));
		for (int i = 1; i < m; ++i)
			trans[0][(i + 1) / 2][i] = trans[0][(n - i + 2) / 2][i] = INV2;
		trans[0][(n / 2 + 2) / 2][m] = 1;
		for (int i = 1; i < 60; ++i)
			for (int j = 1; j <= m; ++j)
				for (int k = 1; k <= m; ++k)
					for (int l = 1; l <= m; ++l)
						trans[i][j][k] = (trans[i][j][k] +
								trans[i - 1][j][l] * trans[i - 1][l][k]) % P;
		while (ptr_k <= q) {
			for (int i = 1; i <= m; ++i) mul[i] = a[i];
			cur = k[ptr_k].first - step;
			for (int i = 0; i < 60; ++i)
				if (cur & 1ll << i) {
					memset(tmp, 0, sizeof(tmp));
					for (int j = 1; j <= m; ++j)
						for (int k = 1; k <= m; ++k)
							tmp[j] = (tmp[j] + mul[k] * trans[i][k][j]) % P;
					memcpy(mul, tmp, sizeof(mul));
				}
			xorsum ^= mul[x] * k[ptr_k].second;
			++ptr_k;
		}
		printf("%lld\n", xorsum);
	}
}

}

int main() {
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	scanf("%d%d%llu", &test, &T, &seed);
	if (test <= 2) sub1::main(); else
	if (test <= 9) sub2::main();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
