#include<bits/stdc++.h>
#define CT cout << "\n-----------------------\n";
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll Inf=1ll<<60;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
const ll mod=998244353;
const ll inv2=(mod+1)/2;
const int N=2000005;
int a[N],qu[N],id[N],b[N],ans[N];
bool cmp(int A,int B){
	return qu[A]<qu[B];
}
int n;
struct Mat{
	int a[155][155];
	Mat(){}
	int* operator [](int x){return a[x];}
	Mat operator *(Mat r)const{
		Mat res;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				res[i][j]=0;
		for(int i=1;i<=n;++i)
			for(int k=1;k<=n;++k)
				for(int j=1;j<=n;++j)
					res[i][j]=(res[i][j]+1ll*a[i][k]*r[k][j])%mod;
		return res;
	}
}pw[61];
int main() {
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int test, T;
	unsigned long long seed;
	cin >> test >> T >> seed;
	for(int Case = 1; Case <= T; Case ++) {
		int q, x;
		long long k_max;
		cin >> n >> q >> x >> k_max;
		int m=n,tim=0;
		while(m%2==0) m/=2,++tim;
		bool sub1=0;
		if(m==1) sub1=1;
		for(int i = 1; i <= n; i ++)
			cin >> a[i];
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			qu[i]=k;
			if(sub1) qu[i]=min(qu[i],tim);
			id[i]=i;
			/*
			Code your solution here.
			*/
		}
		if(k_max<=500){
			sort(id+1,id+q+1,cmp);
			int curk=0;
			for(int i=1;i<=q;++i){
				while(curk<qu[id[i]]){
					for(int j=1;j+j<=n;++j)
						b[j]=a[j]+a[n-j+1];
					for(int j=1;j<=n;++j)
						a[j]=inv2*b[(j+1)>>1]%mod;
					++curk;
				}
				ans[id[i]]=a[x];
			}
			ll tmp=0;
			for(int i=1;i<=q;++i)
				tmp^=1ll*ans[i]*i;
			cout << tmp << '\n';
			continue;
		}
		Mat G;
		for(int i=1;i<=n;++i) 
			for(int j=1;j<=n;++j) G[i][j]=0;
		for(int i=1,j=1;i<=n;i+=2){
			G[i][j]=G[i][n-j+1]=inv2;
			G[i+1][j]=G[i+1][n-j+1]=inv2;
			++j;
		}
		pw[0]=G;
		for(int i=1;i<60;++i)
			pw[i]=pw[i-1]*pw[i-1];
		ll final=0;
		for(int i=1;i<=q;++i){
			Mat tmp;
			for(int j=1;j<=n;++j){
				for(int k=1;k<=n;++k)
					tmp[j][k]=0;
				tmp[j][j]=1;
			}
			int tim=qu[i];
			for(int w=59;~w;--w)
				if(tim>>w&1) tmp=tmp*pw[w];
			int ans=0;
			for(int j=1;j<=n;++j){
				ans=(ans+1ll*a[j]*tmp[j][x])%mod;
			}
			final^=1ll*ans*i;
		}
		cout << final << '\n';
	}
	return 0;
}

