#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

const int mod = 998244353;
int power(int a, ll b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}
int power(int a, ll b, int mod) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}

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

ull seed;
void rmain() {
    int n, q, x;
    long long k_max;
    scanf("%d%d%d%lld", &n, &q, &x, &k_max);
    vector<int> a(n + 1);
    ll sum = 0;
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    sum %= mod;
    ull ans = 0;
    int invn = power(n, mod - 2);
    int x1 = (x + 1) / 2 - 1, x2 = n - x1 - 1;
    map <int, int> mp;
    for(int i = 1; i <= q; i ++) {
        ull k = rd(seed) % k_max;
        if (k == 0) {
            ans ^= 1ll * i * a[x];
            continue;
        }
        k--;
        int restk = power(2, k, n);
        int qwqa = 1ll * (power(2, k, mod) + mod - restk) * invn % mod;
        long long cursum = 0;
        if (mp.count(restk)) cursum = mp[restk];
        else {
            for (int i = 0; i < restk; i++) {
                cursum += a[(1ll * i * n + x1) / restk + 1];
                cursum += a[(1ll * i * n + x2) / restk + 1];
            }
            mp[restk] = cursum %= mod;
        }
        cursum = (cursum + 2ll * qwqa * sum) % mod;
        cursum = 1ll * cursum * power(power(2, k + 1), mod - 2) % mod;
        ans ^= 1ll * cursum * i;
    }
    printf("%llu\n", ans);
}

int main() {
    freopen("noodle.in", "r", stdin);
    freopen("noodle.out", "w", stdout);
	int test, T;
	scanf("%d%d%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) rmain();
}