#include <bits/stdc++.h>
using namespace std;

const int mod = 998244353, iv = (mod + 1) / 2;

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

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);
	for(int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<int> a(n + 1);
		for(int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
		}
		vector<int> ans;
		vector<int> A(n + 1), B(n + 1);
		A[x] = 1, ans.push_back(a[x]);
		for (int i = 1; i < k_max; i++) {
		  for (int j = 1; j <= n / 2; j++) B[j] = 0;
      for (int j = 1; j <= n; j++) (B[(j + 1) / 2] += A[j]) %= mod;
      int ret = 0;
      for (int j = 1; j <= n; j++) {
        A[j] = 1ll * B[min(j, n - j + 1)] * iv % mod;
        (ret += 1ll * A[j] * a[j] % mod) %= mod;
      }
      ans.push_back(ret);
      if (*max_element(A.begin() + 1, A.end()) == *min_element(A.begin() + 1, A.end())) break;
    }
    long long Ans = 0;
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			Ans ^= 1ll * ans[min(k, (long long)ans.size() - 1)] * i;
		}
		printf("%lld\n", Ans);
	}
	return 0;
}
