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

namespace Legendgod {
namespace Read {
//    #define Fread
    #ifdef Fread
    const int Siz = (1 << 21) + 5;
    char *iS, *iT, buf[Siz];
    #define gc() ( iS == iT ? (iT = (iS = buf) + fread(buf, 1, Siz, stdin), iS == iT ? EOF : *iS ++) : *iS ++ )
    #define getchar gc
    #endif // Fread

    template <typename T>
    void r1(T &x) {
        x = 0; char c(getchar()); int f(1);
        for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
        for(; isdigit(c); c = getchar()) x = (x * 10) + (c ^ 48);
        x *= f;
    }
    template <typename T, typename...Args>
    void r1(T &x, Args&...arg) {
        r1(x), r1(arg...);
    }
}

using Read::r1;

const int maxn = 2e6 + 5;
const int mod = 998244353;

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
unsigned long long seed;
long long k_max;
int n, Q, X, a[maxn];
int ksm(int x,int mi) {
    int res(1);
    while(mi) {
        if(mi & 1) res = 1ll * res * x % mod;
        mi >>= 1;
        x = 1ll * x * x % mod;
    }
    return res;
}

int Inv(int x) { return ksm(x, mod - 2); }

const int inv2 = Inv(2);
struct Node {
    int id;
    long long sk;
    bool operator < (const Node& z) const { return sk < z.sk; }
}que[maxn];
int ans[maxn];

namespace Sub1 {
    void Solve() {
        int i, j;
        for(i = 1; i <= Q; ++ i) que[i].sk = rd(seed) % k_max, que[i].id = i;
        sort(que + 1, que + Q + 1);
        for(i = 0, j = 0; j <= Q; ++ i) {
            while(j <= Q && que[j].sk == i) ans[que[j].id] = a[X], ++ j;
            if(j > Q) break;
            for(int k = 1; k <= n / 2; ++ k) a[k] = (a[k] + a[n - k + 1]) % mod;
            for(int k = n / 2; k >= 1; -- k) a[2 * k] = a[2 * k - 1] = 1ll * a[k] * inv2 % mod;
        }
        long long res(0);
        for(i = 1; i <= Q; ++ i) res ^= 1ll * ans[i] * i;
        printf("%lld\n", res);
    }
}

namespace Sub2 {
    void Solve() {
        int i, j;
        for(i = 1; i <= Q; ++ i) que[i].sk = rd(seed) % k_max, que[i].id = i;
        sort(que + 1, que + Q + 1);
        for(i = 0, j = 0; j <= Q && i <= 61; ++ i) {
            while(j <= Q && que[j].sk == i) ans[que[j].id] = a[X], ++ j;
            if(j > Q) break;
            for(int k = 1; k <= n / 2; ++ k) a[k] = (a[k] + a[n - k + 1]) % mod;
            for(int k = n / 2; k >= 1; -- k) a[2 * k] = a[2 * k - 1] = 1ll * a[k] * inv2 % mod;
        }
        while(j <= Q) ans[que[j].id] = a[X], ++ j;
        long long res(0);
        for(i = 1; i <= Q; ++ i) res ^= 1ll * ans[i] * i;
        printf("%lld\n", res);
    }
}

namespace Sub4 {
    bool bg;
    struct Matrix {
        int a[505][505];
        Matrix(void) { memset(a, 0, sizeof(a)); }
        void clear() { memset(a, 0, sizeof(a)); }
        Matrix operator * (const Matrix& z) const {
            Matrix res;
            for(int i = 1; i <= n; ++ i)  for(int k = 1; k <= n; ++ k) {
                for(int j = 1; j <= n; ++ j) {
                    res.a[i][j] = (res.a[i][j] + 1ll * a[i][k] * z.a[k][j]) % mod;
                }
            }
            return res;
        }
        void Print() {
            for(int i = 1; i <= n; ++ i) for(int j = 1; j <= n; ++ j) printf("%d%c", a[i][j], " \n"[j == n]);
        }
    }A, B;
    bool ed;
    int Ksm(Matrix tmp, long long sk) {
//        printf("sk = %lld\n", sk);
        static Matrix res; res.clear();
        for(int i = 1; i <= n; ++ i) res.a[1][i] = a[i];
        while(sk) {
            if(sk & 1) res = res * tmp;
            sk >>= 1;
            tmp = tmp * tmp;
        }
        return res.a[1][X];
    }

    void Solve() {
//        cerr << fabs(&ed - &bg) / 1024.0 / 1024.0 << endl;
        long long res(0);
        int i;
        A.clear(), B.clear();
        for(i = n / 2 + 1; i <= n; ++ i) A.a[i][n - i + 1] = 1;
        for(i = 1; i <= n / 2; ++ i) A.a[i][i] = 1;
        for(i = 1; i <= n / 2; ++ i) B.a[i][2 * i] = B.a[i][2 * i - 1] = inv2;
        A = A * B;
        for(i = 1; i <= Q; ++ i) {
            long long sk = rd(seed) % k_max;
            int ans = Ksm(A, sk);
            res ^= 1ll * i * ans;
        }
        printf("%lld\n", res);
    }
}

signed main() {
    freopen("noodle.in", "r", stdin);
    freopen("noodle.out", "w", stdout);
    int i, j, test, T;
//	scanf("%d%d%llu", &test, &T, &seed);
	r1(test, T), r1(seed);
	for(int Case = 1; Case <= T; ++ Case) {
		r1(n, Q, X), r1(k_max);
		for(i = 1; i <= n; ++ i) r1(a[i]);
//		if(test <= 2) { Sub1::Solve(); continue; }
//		if(test == 3) { Sub2::Solve(); continue; }
//		if(test == 4 || test == 5 || test == 6 || test == 8 || test == 9)
            { Sub4::Solve(); continue; }
		for(i = 1; i <= Q; ++ i) {
			long long k = rd(seed) % k_max;

		}
	}
    return 0;
}
/*
0 1 13
8 2 1 100
1 3 4 8 9 1 2 3

0 1 13
6 2 3 3
6 2 5 3 1 4

*/
}

signed main() { return Legendgod::main(), 0; }
