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

#define ll long long
#define ull unsigned long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define SZ(a) ((int)a.size())
#define pb push_back
#define fir first
#define sec second

inline int read(){
    int x=0,f=0;char ch=getchar();
    while(!isdigit(ch))f|=ch=='-',ch=getchar();
    while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
    return f?-x:x;
}
template<typename T> void print(T x){
    if(x<0)putchar('-'),x=-x;
    if(x>=10)print(x/10);
    putchar(x%10+'0');
}
template<typename T> void print(T x,char ch){
    print(x),putchar(ch);
}

inline void ckmax(ll &x,ll y){
    if(x<y)x=y;
}

const int N=250;
const int mod=998244353;
const ull MOD=1ull*mod*mod;
const int inv2=(mod+1)/2;

int test,T;unsigned long long seed;
int n,q;long long k_max,ask[N];
int cur[100005][N],be[N];

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

inline void add(int &x,int y){
    if((x+=y)>=mod)x-=mod;
}

void solve(){
    int x;
    scanf("%d%d%d%lld",&n,&q,&x,&k_max);
    rep(i,1,n)cur[0][i]=read();
    rep(t,1,100000){
        static int b[N];
        rep(i,1,n/2)b[i]=1ll*(cur[t-1][i]+cur[t-1][n+1-i])*inv2%mod;
        rep(i,1,n)cur[t][i]=b[(i+1)/2];
        // printf("when t=%d,cur=%d\n",t,cur[t][x]);
    }
    ll _=0,result=0;
    rep(i,1,q){
        ll k=rd(seed)%k_max;
        // printf("when i=%d,k=%lld,ans=%d\n",i,k,cur[k][x]);
        result^=1ll*cur[k][x]*i;
    }
    printf("%llu\n",result);
}

int main(){
    scanf("%d%d%llu",&test,&T,&seed);
    while(T--){
        solve();
    }
    return 0;
}

/*
0 1 10
8 1 4 8
8 7 6 5 4 3 2 1
*/