#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pa pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<int>
#define int ll
#define N 2000005
const int mod=998244353;
const int inv2=(mod+1)/2;
const int B=35;
int n, q, x;
long long k_max;
int test, T;
int id[N];
int a[N];
int tim;
int vs[N];
int b[N];
int len;
int st[N][B];
unsigned long long seed;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
struct matrix
{
    int n,m;
    vector<vector<int>>a;
    void reset0(int x,int y)
    {
        n=x,m=y;
        a.clear();
        a.resize(x+1);
        for (auto &u:a) u.resize(y+1);
    }
    matrix()
    {
    }
};
matrix Mt[60];
inline matrix operator * (matrix &a,matrix &b)
{
    matrix res;
    res.reset0(a.n,b.m);
    for (int i=1;i<=b.n;i++)
        for (int j=1;j<=b.m;j++)
            if (b.a[i][j])
            {
                for (int k=1;k<=a.n;k++)
                {
                    res.a[k][j]=(res.a[k][j]+a.a[k][i]*b.a[i][j]%mod);
                    res.a[k][j]=(res.a[k][j]>=mod)?res.a[k][j]-mod:res.a[k][j];
                }
            }
    return res;
}
inline void buildmatrix()
{
    for (int i=1;i<=n;i++)
    {
        if (st[i][B-1]!=st[i-1][B-1]||i==1)
        {
            len++;
        }
        id[i]=len;
    }
    ++tim;
    Mt[0].reset0(len,len);
    for (int i=n/2;i>=1;i--)
    {
        if (vs[id[i*2]]==tim) continue;
        vs[id[i*2]]=tim;
        Mt[0].a[id[i]][id[i*2]]=(Mt[0].a[id[i]][id[i*2]]+inv2)%mod;
        Mt[0].a[id[n-i+1]][id[i*2]]=(Mt[0].a[id[n-i+1]][id[i*2]]+inv2)%mod;
    }
    for (int j=1;j<60;j++)
        Mt[j]=Mt[j-1]*Mt[j-1];
}
signed main() 
{
    freopen("noodle.in","r",stdin);
    freopen("noodle.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>test>>T>>seed;
	for(int Case = 1; Case <= T; Case ++)
    {
        cin>>n>>q>>x>>k_max;
        len=0;
        for (int i=1;i<=n;i++)
        {
            cin>>a[i];
		}
        for (int i=1;i<=n;i++) st[i][0]=a[i];
        for (int tim=1;tim<B;tim++)
        {
            for (int i=1;i<=n;i++)
                b[i]=st[i][tim-1];
            for (int i=1;i<=n-i+1;i++)
            {
                b[i]+=b[n-i+1];
            }
            for (int i=1;i<=n/2;i++)
                st[i*2-1][tim]=b[i]*inv2%mod,st[i*2][tim]=b[i]*inv2%mod;
        }
        buildmatrix();
        matrix revs;
        revs.reset0(1,len);
        for (int i=1;i<=n;i++)  revs.a[1][id[i]]=st[i][B-1];
        int rans=0;
		for(int i=1;i<=q;i++)
        {
			long long k=rd(seed)%k_max;
            if (k<B)
            {
                rans^=st[x][k]*i;
                continue;
            }
            k-=B-1;
            matrix ans;
            ans=revs;
            for (int j=0;j<60;j++)
                if ((k>>j)&1)
                    ans=ans*Mt[j];
            rans^=ans.a[1][id[x]]*i;
		}
        cout<<rans<<endl;
	}
}