#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>

#define ri int
#define ll long long
#define pii pair<int,int>

const ll mod=998244353,inv2=mod+1>>1;
ll add(ll x,ll y){return (x+=y)<mod?x:x-mod;}
ll dec(ll x,ll y){return (x-=y)<0?x+mod:x;}
ll ksm(ll d,ll t,ll res=1){for(;t;t>>=1,d=d*d%mod) if(t&1) res=res*d%mod;return res;}
const int MAXN=2e6+7;
int n,q,x,a[MAXN];
struct Matrix{
    ll w[501][501];
    void init(){for(ri i=1;i<=n;++i) for(ri j=1;j<=n;++j) w[i][j]=0;}
};
const ll MOD=mod*mod;
Matrix operator*(const Matrix &a,const Matrix &b){
    Matrix c;c.init();
    for(ri i=1;i<=n;i++) for(ri k=1;k<=n;++k) for(ri j=1;j<=n;++j){
        c.w[i][j]+=a.w[i][k]*b.w[k][j];
        if(c.w[i][j]>=MOD) c.w[i][j]-=MOD;
    }
    for(ri i=1;i<=n;++i){
        for(ri j=1;j<=n;++j) c.w[i][j]%=mod;
        // for(ri x=i+1;x<i+4&&x<=n;++x) for(ri j=1;j<=n;++j) c.w[][]
    }
    return c;
}
Matrix operator/(const Matrix &a,const Matrix &b){
    Matrix c;c.init();
    for(ri i=1;i<=n;i+=4) for(ri k=1;k<=n;++k) for(ri j=1;j<=n;++j){
        c.w[i][j]+=a.w[i][k]*b.w[k][j];
        if(c.w[i][j]>=MOD) c.w[i][j]-=MOD;
    }
    for(ri i=1;i<=n;i+=4){
        for(ri j=1;j<=n;++j) c.w[i][j]%=mod;
        for(ri x=i+1;x<i+4&&x<=n;++x) for(ri j=1;j<=n;++j) c.w[x][j]=c.w[i][j];
    }
    return c;
}
Matrix operator^(const Matrix &a,const Matrix &b){
    Matrix c;c.init();
    for(ri i=1;i<=n;++i) for(ri k=1;k<=n;++k) c.w[1][i]=add(c.w[1][i],a.w[i][k]*b.w[1][k]%mod);
    return c;
}

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

ll K,k;
ll ans;
namespace Sub1{
    Matrix G[64],V;
    void init(){
        G[0].init();
        for(ri i=1;i<=n;++i){
            int j=i+1>>1;
            G[0].w[i][j]=G[0].w[i][n-j+1]=inv2;
        }
        for(ri i=1;i<=3;++i) G[i]=G[i-1]*G[i-1];
        for(ri i=4;i<=60;++i) G[i]=G[i-1]/G[i-1];
    }
    int main(){
        V.init();
        for(ri i=1;i<=n;++i) V.w[1][i]=a[i];
        for(ri i=0;i<64;++i) if(k>>i&1) V=G[i]^V;
        ans=V.w[1][x];
        return 0;
    }
}
namespace Sub2{
    int tmp[MAXN],resa[MAXN],resans[MAXN];
    void init(){
        for(ri i=1;i<=n;++i) resa[i]=a[i];
        resans[0]=resa[x];
        for(ri t=1;t<=K;++t){
            for(ri i=1;i<=n;++i) tmp[i]=resa[i];
            for(ri i=1;i<=n;++i){
                int j=i+1>>1;
                resa[i]=add(tmp[j],tmp[n-j+1])*inv2%mod;
            }
            resans[t]=resa[x];
        }
    }
    int main(){
        ans=resans[k];
        return 0;
    }
}
namespace Sub3{
    int tmp[MAXN],resa[MAXN],resans[MAXN];
    void init(){
        for(ri i=1;i<=n;++i) resa[i]=a[i];
        resans[0]=resa[x];
        for(ri t=1;t<=32;++t){
            for(ri i=1;i<=n;++i) tmp[i]=resa[i];
            for(ri i=1;i<=n;++i){
                int j=i+1>>1;
                resa[i]=add(tmp[j],tmp[n-j+1])*inv2%mod;
            }
            resans[t]=resa[x];
        }
    }
    int main(){
        ans=resans[std::min(k,32ll)];
        return 0;
    }
}
int main() {
    freopen("noodle.in","r",stdin);
    freopen("noodle.out","w",stdout);
	int test, T;
	unsigned long long seed;
	scanf("%d%d%llu", &test, &T, &seed);
	while(T--){
        ans=0;
		scanf("%d%d%d%lld",&n,&q,&x,&K);
        for(ri i=1;i<=n;++i) scanf("%d",&a[i]);
        int typ=0;
        if(__builtin_popcount(n)==1) typ=3;
        else if(K<=500000000/n) typ=2;
        else if(n<=500) typ=1;
        if(typ==1) Sub1::init();
        if(typ==2) Sub2::init();
        if(typ==3) Sub3::init();
        ll totans=0;
		for(ri i=1;i<=q;++i){
			k = rd(seed) % K;
            if(typ==1) Sub1::main();
            if(typ==2) Sub2::main();
            if(typ==3) Sub3::main();
            totans^=1ll*i*ans;
            // printf("%lld\n",ans);
		}
        printf("%lld\n",totans);
	}
}