#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+5,mod=998244353,inv2=(mod+1)/2;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
unsigned long long seed;
int a[N];
vector<int> b[505];
void add(int &x,int y){
	x+=y;if(x>=mod) x-=mod;
}
struct matrix{
	int a[155][155],n,m;
	matrix(){ memset(a,0,sizeof(a));}
	friend matrix operator * (const matrix &a, const matrix &b) {
		matrix res;
		res.n=a.n,res.m=b.m;
		for(int i=1;i<=a.n;++i)
			for(int j=1;j<=b.m;++j)
				for(int k=1;k<=min(a.m,b.n);++k)
					res.a[i][j]=(res.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%mod;
		return res;
	}
}mt[60];
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=1ll*res*b%mod;
		b=1ll*b*b%mod; n>>=1;
	}
	return res;
}
void solve(){
	int n, q, x;
	long long k_max;
	cin >> n >> q >> x >> k_max;
	b[0].resize(n+1);
	for(int i=1;i<=n;++i)
		cin>>a[i],b[0][i]=a[i];
	if(k_max<=50||max((ll)n,k_max)<=500||__builtin_popcount(n)==1){
		int lim=k_max;
		if(__builtin_popcount(n)==1) lim=21;
		for(int i=1;i<=lim;++i){
			b[i].resize(n+1);
			for(int j=1;j<=n;++j)
				b[i][j]=1ll*(b[i-1][(j+1)/2]+b[i-1][n+1-(j+1)/2])*inv2%mod;			
		}
	}
	else{
		mt[0].n=mt[0].m=n;
		for(int i=1;i<=n;++i)
			mt[0].a[i][(i+1)/2]=mt[0].a[i][n+1-(i+1)/2]=1;
		for(int i=1;i<60;++i) mt[i]=mt[i-1]*mt[i-1];
	}
	long long res=0;
	for(int i=1;i<=q;++i){
		long long k = rd(seed) % k_max;
		int ans=0;
		if(k_max<=50||max((ll)n,k_max)<=500) ans=b[k][x],cerr<<ans<<"\n";
		else if(__builtin_popcount(n)==1) ans=b[min(21ll,k)][x];
		else{
			matrix fuck;
			fuck.n=n,fuck.m=1;
			for(int i=1;i<=n;++i)
				fuck.a[i][1]=a[i];
			for(int i=1;i<60;++i)
				if(k>>i&1) fuck=mt[i]*fuck;
			ans=fuck.a[x][1];
		}
		res^=1ll*ans*i;
	}
	cout<<res<<"\n";
}
signed main() {
	freopen("noodle.in","r",stdin);
	freopen("noodle.ans","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int test, T;
	cin >> test >> T >> seed;
	while(T--) solve();
}
