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

typedef unsigned long long ull;
typedef long long ll;

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

const int maxn = 2000005;
const int p = 998244353, inv2 = (p + 1) / 2;
int n, x, nn;
int a[maxn];
ll aX[maxn << 1];
bool vis[maxn << 1];

pair<int, int> qpow(ll k) {
    int ansL = 0, ansX = 1;
    int aL = 0, aX = 2;
    while (k) {
        if (k & 1) {
            ansL = (1LL * ansL * aL % p * nn + 1LL * ansL * aX + 1LL * aL * ansX) % p;
            ansL = (ansL + 1LL * ansX * aX / nn) % p;
            ansX = 1LL * ansX * aX % nn;
        }
        aL = (1LL * aL * aL % p * nn + 2LL * aL * aX) % p;
        aL = (aL + 1LL * aX * aX / nn) % p;
        aX = 1LL * aX * aX % nn;
        k >>= 1;
    }
    return make_pair(ansL, ansX);
}
int qpowi2(ll k) {
    int ans = 1, a = inv2;
    while (k) {
        if (k & 1) ans = 1LL * ans * a % p;
        a = 1LL * a * a % p;
        k >>= 1;
    }
    return ans;
}

int main() {
    freopen("noodle.in", "r", stdin);
    freopen("noodle.out", "w", stdout);
	int test, T;
	ull seed;
	scanf("%d%d%llu", &test, &T, &seed);

	while (T--) {
		int q;
		ll k_max;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);
        // n = (rand() % 500000) * 2 + 1000000;
        x -= 1;
        nn = n + n;
        ll sa = 0;
		for(int i = 0; i < n; i++) sa += a[i];
        sa %= p;
        
        memset(vis, 0, sizeof(bool) * nn);
        int cnt = 0;
        for (int X = 1; !vis[X]; X = (X + X) % nn, cnt++) {
            vis[X] = 1;
            aX[X] = 0;
            if (X) {
                ll px = x;
                while (px / X < n) {
                    aX[X] += a[px / X];
                    px += nn;
                }
                px = nn - 1 - x;
                while (px / X < n) {
                    aX[X] += a[px / X];
                    px += nn;
                }
            }
            aX[X] %= p;
        }
        // printf("cnt = %d\n", cnt);

        ull ANS = 0;
		for (int _ = 1; _ <= q; _++) {
			ll k = rd(seed) % k_max;

            pair<int, int> LX = qpow(k);
            int ans = (2LL * LX.first * sa + aX[LX.second]) % p;
            ans = 1LL * ans * qpowi2(k) % p;
            ANS ^= (ull)ans * _;
		}
        printf("%llu\n", ANS);
	}
}