//ZJOI is 2 hd 4 me
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
inline int read()
{
    int r=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') r=r*10+c-48,c=getchar();
    return r;
}
inline ull rd(ull &x) 
{
	x^=(x<<13),x^=(x>>7),x^=(x<<17);
	return x;
}
const int p=998244353,h=(p+1)>>1;
int a[22][2000003],val[153];
struct mat{int a[153][153];}tmp[61];
mat mul(mat &A,mat &B,int sz)
{
    mat C;
    for(int i=1; i<=sz; ++i) memset(C.a[i],0,(sz+1)<<2);
    for(int i=1; i<=sz; ++i)
        for(int j=1; j<=sz; ++j)
            for(int k=1; k<=sz; ++k)
                C.a[i][j]=(C.a[i][j]+1ll*A.a[i][k]*B.a[k][j])%p;
    return C;
}
int calc(ull x,int pos,int sz)
{
    mat r;
    for(int i=1; i<=sz; ++i) memset(r.a[i],0,(sz+1)<<2);
    for(int i=1; i<=sz; ++i) r.a[i][i]=1;
    for(ull i=x,j=0; i; i>>=1,++j) (i&1)&&(r=mul(r,tmp[j],sz),0);
    int res=0;
    for(int i=1; i<=sz; ++i) 
        res=(res+1ll*val[i]*r.a[i][pos])%p;
    return res;
}
int aa[503][503];
signed main()
{
#ifndef local
    freopen("noodle.in","r",stdin);
    freopen("noodle.out","w",stdout);
#endif
    ull seed,lim,v,ans;
    int id=read(),T=read();
    scanf("%llu",&seed);
    while(T--)
    {
        int n=read(),q=read(),x=read(),N=n,X=x,g=1,sz;
        scanf("%llu",&lim),ans=0;
        if(n<=500&&q<=500&&lim<=500)
        {
            for(int i=1; i<=n; ++i) aa[0][i]=read();
            for(int s=1; s<=lim; ++s)
                for(int i=1; i<=n; ++i)
                    aa[s][(i<<1)-1]=aa[s][i<<1]=1ll*(aa[s-1][i]+aa[s-1][n+1-i])*h%p;
            for(int i=1; i<=q; ++i)
            {
                v=rd(seed)%lim;
                ans^=1ull*i*aa[v][x];
            }
            printf("%llu\n",ans);
            continue;
        }
        while(!(N&1)) N>>=1,(++X)>>=1,g<<=1;
        sz=(N+1)>>1,g<<=1,(++X)>>=1;
        for(int i=1; i<=n; ++i) a[0][i]=read();
        for(int s=1; s<=21; ++s)
            for(int i=1; i<=n; ++i)
                a[s][(i<<1)-1]=a[s][i<<1]=1ll*(a[s-1][i]+a[s-1][n+1-i])*h%p;
        if(sz<150)
        {
            for(int i=1; i<=sz; ++i) memset(tmp[0].a[i],0,(sz+1)<<2);
            for(int i=1; i<=sz; ++i) val[i]=a[21][(i-1)*g+1];
            for(int i=1; i<sz; ++i)
                tmp[0].a[(i+1)>>1][i]=tmp[0].a[(N-i+2)>>1][i]=h;
            tmp[0].a[(sz+1)>>1][sz]=1;
            for(int i=1; i<=60; ++i) tmp[i]=mul(tmp[i-1],tmp[i-1],sz);
        }
        for(int i=1; i<=q; ++i)
        {
            v=rd(seed)%lim;
            if(v<=21) ans^=1ull*i*a[v][x];
            else if(sz==1) ans^=1ull*i*val[1];
            else ans^=1ull*i*calc(v-21,X,sz); 
        }
        printf("%llu\n",ans);
    }
    return 0;
}