#include <bits/stdc++.h>
namespace Qiaoqia {
constexpr int N = 200'0005, P = 998244353;

long long n, q, x, km, a[N], res[N], inv2;
unsigned long long seed;

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

long long Pow(long long a, long long b) {
	long long an = 1;
	for ( ; b; b >>= 1, a = a * a % P)
		if (b & 1) an = an * a % P;
	return an;
}

std::vector<int> trans(std::vector<int> a, int k) {
	for (int i = 1; i <= k; i++) {
		std::vector<int> b(n + 1);
		for (int j = 1; j <= n / 2; j++) b[j] = a[j] + a[n - j + 1];
		for (int j = 1; j <= n; j++)
			a[j] = 1ll * inv2 * b[(j + 1) / 2] % P;
	}
	return a;
}

void bf() {
	std::cin >> n >> q >> x >> km;
	std::vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	long long ans = 0;
	for (int i = 1; i <= q; i++) {
		long long k = rd(seed) % km;
		long long an = trans(a, k)[x];
		ans ^= an * i;
	}
	std::cout << ans << '\n';
}

void allk(int op = 0) {
	std::cin >> n >> q >> x >> km;
	std::vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	res[0] = a[x];
	for (int i = 1; i < (!op ? km : op); i++) {
		std::vector<int> b(n + 1);
		for (int j = 1; j <= n / 2; j++) b[j] = a[j] + a[n - j + 1];
		for (int j = 1; j <= n; j++)
			a[j] = 1ll * inv2 * b[(j + 1) / 2] % P;
		res[i] = a[x];
	}
	long long ans = 0;
	for (int i = 1; i <= q; i++) {
		long long k = rd(seed) % km;
		if (!op) ans ^= 1ll * res[k] * i % P;
		else ans ^= 1ll * res[std::min(k, 1ll * op)] * i % P;
	}
	std::cout << ans << '\n';
}

void fpow() { allk(20); }


struct kk {
	int a[55][55], n;
	kk(int _n) { memset(a, 0, sizeof a); n = _n; }
	int* operator [](int x) { return a[x]; }
	kk operator * (kk b) {
		kk a = *this;
		kk c(a.n);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				for (int k = 1; k <= n; k++)
					c[i][j] = (c[i][j] + 1ll * a[i][k] * b[k][j] % P) % P;
		return c;
	}
} f(0);

kk Powkk(kk a, int b) {
	kk an(a.n);
	for (int i = 1; i <= a.n; i++)
		an[i][i] = 1;
	for ( ; b; b >>= 1, a = a * a)
		if (b & 1) an = an * a;
	return an;
}
void pow(int n, int k) {
	f.n = n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			f[i][j] = 0;
	for (int i = 1; i <= n; i++) {
		int d = (i + 1) / 2;
		f[i][d] = f[i][n - d + 1] = 1;
	}
	f = Powkk(f, k);
}

void mpow() {
	std::cin >> n >> q >> x >> km;
	std::vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	long long ans = 0;
	for (int i = 1; i <= q; i++) {
		long long k = rd(seed) % km;
		pow(n, k);
		long long an = 0;
		for (int j = 1; j <= n; j++) 
			an = (an + 1ll * f[x][j] * a[j] % P) % P;
		an = an * Pow(inv2, k) % P;
		ans ^= an * i;	
	}
	std::cout << ans << '\n';
}

void p2m3() {
	std::cin >> n >> q >> x >> km;
	std::vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	int sum0 = 0, sum2 = 0;
	for (int i = 1; i <= n; i++)
		if (i % 3 == 2) sum2 = (sum2 + a[i]) % P;
		else sum0 = (sum0 + a[i]) % P;	
	long long ans = 0;
	for (int i = 1; i <= q; i++) {
		long long k = rd(seed) % km;
		pow(6, k);
		long long an;
		if (x > n / 3 * 2) an = (sum0 * f[5][1] % P + sum2 * f[5][2] % P) % P;
		else an = (sum0 * f[1][1] % P + sum2 * f[1][2] % P) % P;
		an = an * Pow(inv2, k);
		ans ^= an * i;	
	}
	std::cout << ans << '\n';
}

void main() {
	int test, T;
	std::cin >> test >> T >> seed;
	inv2 = Pow(2, P - 2);
	while (T--) 
		if (test == 1) bf();
		else if (test == 2) allk();
		else if (test == 3) fpow();
		else if (test >= 4 && test <= 6) mpow();
		else if (test == 7) p2m3();
}
}
void _() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }
int main() { void IO(); IO(); _(); Qiaoqia::main(); }
void IO() {
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
}
