#include <stdio.h>
#include <string.h>
#include <set>
#include <algorithm>
#include <vector>
#define int long long
const int mod = 998244353;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
inline int qp(int x, int p)
{
	// p %= mod
	int res = 1;
	while(p)
	{
		if(p & 1)res = res * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return res;
}
signed main() {
    freopen("noodle.in", "r", stdin);
    freopen("noodle.out", "w", stdout);
	int test, T;
	unsigned long long seed;
	scanf("%lld%lld%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max;
		scanf("%lld%lld%lld%lld", &n, &q, &x, &k_max);
		std::vector<int> a(n + 1), pre(n + 1), l(1), r(1), vis(n * 2 + 1), vk(n * 2 + 1), lt(n * 2 + 1);
        // std::vector<std::vector<int>> id[3];
		int length = 1;
		l[0] = r[0] = x; 
		for(int i = 1; i <= n; i ++) {
			scanf("%lld", &a[i]);
			pre[i] = (a[i] + pre[i - 1]) % mod;
		}
		int circStart, circEnd;
		for(int i = 0; i <= n * 2 + 1; i ++) {
			if(vis[length]) {
				circStart = vis[length];
				circEnd = i - 1;
                break;
			}
			vis[length] = i;
			if(length == 0) length = n * 2;
            // lt.push_back(length);
            lt[i] = length;
            // std::vector<int> d[3];
            int l = 1, r = length;
            int dn = 0;
            for(int j = 1; j <= n; j++)
            {
                int xx[4] = {x, n * 2 - x + 1, x + 2 * n, 4 * n - x + 1};
                int count = 0;
                l = l % (2 * n);
                r = r % (2 * n);
                if(l == 0)l = 2 * n;
                if(r == 0)r = 2 * n;
                if(l > r)r += 2 * n;
                for(int p = 0; p < 4; p++)count += (l <= xx[p] && xx[p] <= r);
                dn += count * a[j];
                // printf ("count %d %d = %d .. %d %d\n",j,length,count,l,r);
                // d[count].push_back(j);
                l += length;
                r += length;
            }
            // for(int p = 0; p < 3; p++)id[p].push_back(d[p]);
            // vk.push_back(dn);
            vk[i] = dn;
            // printf("dn = %d\n",dn);
			// l.push_back(1); r.push_back(length);
			// l[i] += length * (x - 1) % n;
			// r[i] += length * (x - 1) % n;
			// if(l[i] == 0)l[i] = n;
			// if(r[i] == 0)r[i] = n;
			length = length * 2 % (2 * n);
		}
        int debug=0;
        // for(auto x:vk)printf("D %d %d\n",debug++,x);
		int sum = pre[n] % mod;
        int F = 0;
		int aver = sum * qp(n, mod - 2) % mod;
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			int L, R;
			int ans = 0, len, vK;
			if(k <= circEnd) {
				// L = l[k];
				// R = r[k];
                len = lt[k];
                vK = vk[k];
			}
			else {
				int val = (k - circStart) % (circEnd - circStart) + circStart;
				// L = l[val];
				// R = r[val];
                len = lt[val];
                vK = vk[val];
			}
            // printf ("%lld %lld\n", L , R);
			if(len < 0)len += n;
            // printf("%lld %lld\n",len,vK);
			ans = (qp(2, k) - len % mod + mod) * aver % mod;
			// if(L <= R)ans = (ans + pre[R] - pre[L - 1]) % mod;
			// else ans = (ans + sum - pre[L - 1] + pre[R] + mod) % mod;
            ans = (ans + vK) % mod;
			// printf("%lld\n",
            F ^= i * (ans * qp(mod + 1 >> 1, k) % mod);
			/*
			Code your solution here.
			*/
		}
        printf("%lld\n",F);
	}
}