/**
 * @file noodle.cpp
 * @author Macesuted (i@macesuted.moe)
 * @date 2022-05-04
 *
 * @copyright Copyright (c) 2022
 */

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

bool mem1;

template <typename T = int>
T read(void) {
    T f = +1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -f;
        c = getchar();
    }
    while ('0' <= c && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    return f * x;
}
template <typename T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar((x % 10) ^ 48);
    return;
}

#define maxn 2000005
#define maxlgn 22
#define maxlgv 62
#define mod 998244353

class Matrix {
   private:
    vector<vector<int64_t>> a;
    int n, m;

   public:
    void resize(int _n, int _m) { return a.clear(), a.resize(n = _n, vector<int64_t>(m = _m, 0)); }
    vector<int64_t>& operator[](int x) { return a[x]; }
    int64_t get(int x, int y) const { return a[x][y]; }
    Matrix operator*(const Matrix& o) const {
        assert(m == o.n);
        Matrix ans;
        ans.resize(n, o.m);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                for (int k = 0; k < o.m; k++)
                    ans[i][k] = (ans[i][k] + this->get(i, j) * o.get(j, k)) % mod;
        return ans;
    }
};

int64_t Pow(int64_t a, int64_t x) {
    int64_t ans = 1;
    while (x) {
        if (x & 1) ans = ans * a % mod;
        a = a * a % mod, x >>= 1;
    }
    return ans;
}
int64_t Inv(int64_t a) { return Pow(a, mod - 2); }

const int64_t inv2 = Inv(2);

int test;
uint64_t seed;

int a[maxlgn][maxn], b[505][505];
Matrix mat[maxlgv];

uint64_t rnd(void) { return seed ^= (seed << 13), seed ^= (seed >> 7), seed ^= (seed << 17); }

void solve(void) {
    int n = read(), q = read(), x = read() - 1;
    int64_t kMax = read<int64_t>();
    for (int i = 0; i < n; i++) a[0][i] = read();
    if (kMax <= 500) {
        for (int i = 0; i < n; i++) b[0][i] = a[0][i];
        for (int i = 1; i < kMax; i++)
            for (int j = 0, p = 0; j < n; j += 2, p++)
                b[i][j] = b[i][j + 1] = (b[i - 1][p] + b[i - 1][n - 1 - p]) * inv2 % mod;
        uint64_t ans = 0;
        for (int i = 0; i < q; i++) ans ^= (uint64_t)b[rnd() % kMax][x] * (i + 1);
        write(ans), putchar('\n');
        return;
    }
    if (n <= 150) {
        Matrix A;
        A.resize(1, n);
        for (int i = 0; i < n; i++) A[0][i] = a[0][i];
        mat[0].resize(n, n);
        for (int i = 0, p = 0; i < n; i += 2, p++)
            mat[0][p][i] = mat[0][p][i + 1] = mat[0][n - 1 - p][i] = mat[0][n - 1 - p][i + 1] = inv2;
        for (int i = 1; i < maxlgv; i++) mat[i] = mat[i - 1] * mat[i - 1];
        uint64_t ans = 0;
        for (int i = 0; i < q; i++) {
            int64_t k = rnd() % kMax;
            Matrix B = A;
            for (int j = maxlgv - 1; ~j; j--)
                if (k >> j & 1) B = B * mat[j];
            ans ^= (uint64_t)B[0][x] * (i + 1);
        }
        write(ans), putchar('\n');
        return;
    }
    for (int i = 1; i < maxlgn; i++)
        for (int j = 0, p = 0; j < n; j += 2, p++)
            a[i][j] = a[i][j + 1] = (a[i - 1][p] + a[i - 1][n - 1 - p]) * inv2 % mod;
    uint64_t ans = 0;
    for (int i = 0; i < q; i++) ans ^= (uint64_t)a[min(rnd() % kMax, (uint64_t)maxlgn - 1)][x] * (i + 1);
    write(ans), putchar('\n');
    return;
}

bool mem2;

int main() {
    ios::sync_with_stdio(false);
#ifndef MACESUTED
    freopen("noodle.in", "r", stdin), freopen("noodle.out", "w", stdout);
#endif
#ifdef MACESUTED
    cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

    test = read();
    int _ = read();
    seed = read<uint64_t>();
    while (_--) solve();

#ifdef MACESUTED
    cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
    return 0;
}