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

const int mod = 998244353;
int Mod(int x) { return x >= mod ? x - mod : x; }
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;
}


int f[40][2000010], sum[40][2000010], sumi[40][2000010];
int solve(int dep, int n, int a, int b, int c) {
    if (n == 0) return 0;
    if (a < 0 || a >= c) {
        int qwq = a / c;
        a %= c;
        if (a < 0) a += c, qwq--;
        qwq += mod;
        return (1ll * qwq * sumi[dep][n] + solve(dep, n, a, b, c)) % mod;
    }
    if (b < 0 || b >= c) {
        int qwq = b / c;
        b %= c;
        if (b < 0) b += c, qwq--;
        qwq += mod;
        return (1ll * qwq * f[dep + 1][n] + solve(dep, n, a, b, c)) % mod;
    }
    if (a == 0) return 0;
    int nxtn = (1ll * a * n + b) / c;
    int ans = 1ll * nxtn * f[dep + 1][n] % mod;
    // int ans = 1ll * n * f[dep][nxtn] % mod;
    // ans = Mod(ans + mod - solve(dep + 1, nxtn, c, -b - 1, a));
    for (int j = 1; j <= (a * n + b) / c; j++) {
        ans = Mod(ans + mod - f[dep + 1][(j * c - 1 - b) / a]);
    }
    return ans;
}

ull seed;
void rmain() {
    int n, q, x;
    long long k_max;
    scanf("%d%d%d%lld", &n, &q, &x, &k_max);
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &f[0][i]);
    }
    int ax = f[0][x];
    for (int i = 1; i < 40; i++)
        for (int j = 1; j <= n; j++) f[i][j] = Mod(f[i - 1][j] + f[i][j - 1]);
    for (int i = 0; i < 40; i++) {
        for (int j = 1; j <= n; j++) {
            sumi[i][j] = (sumi[i][j - 1] + 1ll * j * f[i][j]) % mod;
        }
    }

    ull ans = 0;
    int invn = power(n, mod - 2);
    int x1 = (x + 1) / 2 - 1, x2 = n - x1 - 1;
    for(int i = 1; i <= q; i ++) {
        ull k = rd(seed) % k_max;
        if (k == 0) {
            ans ^= 1ll * i * ax;
            continue;
        }
        k--;
        ll restk = power(2, k, n);
        int qwqa = 1ll * (power(2, k, mod) + mod - restk) * invn % mod;
        
        ll cursum = 0;

        cursum = (2ll * qwqa * f[1][n] + solve(0, n, restk, -x1 - 1, n) + solve(0, n, restk, -x2 - 1, n) - solve(0, n, restk, -x1 - 1 - restk, n) - solve(0, n, restk, -x2 - 1 - restk, n) + 2 * mod) % mod;

        cursum = 1ll * cursum * power(power(2, k + 1), mod - 2) % mod;
        ans ^= 1ll * cursum * i;
    }
    printf("%llu\n", ans);
}

int main() {
	int test, T;
	scanf("%d%d%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) rmain();
}