#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i) 
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define sz(a) ((int) (a).size())
#define vi vector < int > 
#define me(a, x) memset(a, x, sizeof(a)) 
#define ll long long
using namespace std;
const int N = 2e6 + 7, mod = 998244353, inv2 = (mod + 1) / 2;


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

unsigned long long seed;
	
const int K = 50;
int a[N], f[K + 2][N];
int hf[505][505];
void Main() {
	int n, q, x;
	long long k_max;
	cin >> n >> q >> x >> k_max;
	L(i, 1, n) cin >> a[i], f[0][i] = a[i];
	if(k_max <= 500 && n <= 500) {
		L(i, 1, n) hf[0][i] = a[i];
		L(i, 1, K) 
			L(j, 1, n / 2) 
				hf[i][j * 2 - 1] = hf[i][j * 2] = (ll) (hf[i - 1][j] + hf[i - 1][n - j + 1]) * inv2 % mod;
		
		ll sum = 0;
		L(o, 1, q) {
			long long k = rd(seed) % k_max;
			sum ^= (ll) hf[min(k, (ll) K)][x] * o;
		}
		cout << sum << '\n';
		return ;
	}
	L(i, 1, K) 
		L(j, 1, n / 2) 
			f[i][j * 2 - 1] = f[i][j * 2] = (ll) (f[i - 1][j] + f[i - 1][n - j + 1]) * inv2 % mod;
	
	int lg = __builtin_ctz(n);
	ll sum = 0;
	if(n == (1 << lg)) {
		L(o, 1, q) {
			long long k = rd(seed) % k_max;
			sum ^= (ll) f[min(k, (ll) K)][x] * o;
		}
		cout << sum << '\n';
		return ;
	}
	int xn = n >> lg;
	
	L(o, 1, q) {
		long long k = rd(seed) % k_max;
		sum ^= (ll) f[min(k, (ll) K)][x] * o;
	}
	cout << sum << '\n';
}

int main() {
//	return system("fc noodle.out noodle_ex2.ans"), 0;
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int test, T;
	cin >> test >> T >> seed;
	while(T--) {
		Main();
	}
	return 0;
}
