#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int Mod=998244353;
const int inv2=(Mod+1)/2;
int a[2100000],b[2100000],val[2100000];
ull rd(ull &x){
	x^=(x<<13);
	x^=(x>>7);
	x^=(x<<17);
	return x;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t,T; ull seed;
	cin>>t>>T>>seed;
	for (int Case=1;Case<=T;Case++){
		int n,q,x; ll k_max;
		cin>>n>>q>>x>>k_max;
		for (int i=1;i<=n;i++) cin>>a[i];
		val[0]=a[x];
		ll mx=0;
		for (int j=1;j<=k_max;j++){
			bool f=true;
			for (int i=1;i<=n;i++){
				b[i]=1ll*(a[(i+1)>>1]+a[n-((i+1)>>1)+1])*inv2%Mod;
				if (b[i]!=a[i]) f=false;
			}
			val[j]=b[x];
			mx=j; if (f) break;
			for (int i=1;i<=n;i++) a[i]=b[i];
		}
		ll ans=0;
		for (int i=1;i<=q;i++){
			ll k=rd(seed)%k_max;
			k=min(k,(ll)mx); ans^=1ll*val[k]*i;
		}
		cout<<ans<<'\n';
	}
	return 0;
}
