#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=2000005;
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[26][N],be[N];

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

struct mat{
    vector<vector<int>> a;
}pw[60];
mat operator * (const mat&a,const mat&b){
    mat c;
    int n=a.a.size();
    c.a.resize(n);
    rep(i,0,n-1)c.a[i].resize(n);
    rep(i,0,n-1){
        rep(j,0,n-1){
            ull now=0;
            rep(k,0,n-1){
                now=now+1ull*a.a[i][k]*b.a[k][j];
                if(now>=MOD)now-=MOD;
            }
            c.a[i][j]=now%mod;
        }
    }
    return c;
}

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

vector<int> operator * (vector<int> a,mat b){
    int n=a.size();
    vector<int> c(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            c[j]=(c[j]+1ull*a[i]*b.a[i][j])%mod;
        }
    }
    return c;
}

void solve(){
    int x;
    scanf("%d%d%d%lld",&n,&q,&x,&k_max);
    rep(i,1,n)cur[0][i]=read();
    // cerr<<"!\n";
    rep(t,1,25){
        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]);
    }
    // cerr<<"ok!\n";
    ll _=0;
    rep(i,1,q){
        ll k=rd(seed)%k_max;
        // printf("When i=%d,k=%lld\n",i,k);
        ask[i]=k;
        ckmax(_,k);
    }
    if(_<=25){
        // cerr<<"in!\n";
        ull result=0;
        rep(i,1,q){
            // printf("ask[%d]=%d\n",i,ask[i]);
            // printf("x=%d\n",x);
            // print(cur[ask[i]][x],'\n');
            // printf("%d\n",cur[ask[i]][x]);
            result^=1ll*cur[ask[i]][x]*i;
        }   
        print(result,'\n');
        return;
    }

    // rep(i,1,n)printf("%d ",cur[25][i]);puts("");

    vector<int> vec;
    int las=0,blo=-1;
    rep(i,1,n){
        if(i==n||cur[25][i]!=cur[25][i+1]){
            ++blo;
            rep(j,las+1,i)be[j]=blo;
            las=i;
            vec.pb(cur[25][i]);
        }
    }
    
    // cerr<<"blo="<<blo<<'\n';
    // return;

    pw[0].a.resize(blo+1);
    rep(i,0,blo)pw[0].a[i].resize(blo+1);
    rep(i,1,n){
        if(i==n||be[i]!=be[i+1]){
            int j=(i+1)/2;
            int k1=be[j],k2=be[n+1-j];
            // printf("here i=%d,j=%d,k1=%d,k2=%d\n",i,j,k1,k2);
            add(pw[0].a[k1][be[i]],inv2);
            add(pw[0].a[k2][be[i]],inv2);
        }
    }
/*
    printf("pw[0]=\n");
    rep(i,0,blo){
        rep(j,0,blo)
            printf("%d ",pw[0].a[i][j]);
        puts("");
    }

    printf("vec=");
    rep(i,0,blo)printf("%d ",vec[i]);puts("");
*/
    for(int bit=1;1ll<<bit<=_;bit++){
        pw[bit]=pw[bit-1]*pw[bit-1];
    }
    ull result=0;
    // int S=0;
    rep(i,1,q){
        ll k=ask[i];
        if(blo==0){
            k=min(k,25ll);
        }
        if(k<=25){
            result^=1ll*cur[k][x]*i;
            // print(cur[k][x],'\n');
            continue;
        }
        k-=25;
        vector<int> tt=vec;

/*
        printf("tt=");
        rep(i,0,blo)printf("%d ",tt[i]);puts("");
*/

        per(i,59,0)
            if(k>>i&1)
                // S++,
                // printf("mul by %d\n",i),
                tt=tt*pw[i];
/*
        printf("tt=");
        rep(i,0,blo)printf("%d ",tt[i]);puts("");

        printf("i=%d,k=%lld,ans=%lld\n",i,k+25,tt[be[x]]);
*/
        result^=1ll*tt[be[x]]*i;
        // print(tt[be[x]],'\n');
    }
    // fprintf(stderr,"S=%d\n",S);
    printf("%llu\n",result);
}

int main(){
    freopen("noodle.in","r",stdin);
    freopen("noodle.out","w",stdout);
    scanf("%d%d%llu",&test,&T,&seed);
    // T=1;
    while(T--){
        solve();
    }
    return 0;
}