#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define int unsigned long long
const int N=200005,mod=998244353;
int n,a[N],b[N],vx[100];
int test,T,q,x,kmax;
int rd(int &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
struct mat{
	int a[205][205],sz;
	void clear(){
		memset(a,0,sizeof(a));
		sz=0;
	}
}v0,A;
mat operator * (const mat &a,const mat &b){
	mat c;
	c.clear();
	int n=a.sz;
	rep(i,0,n){
		rep(j,0,n){
			rep(k,0,n){
				c.a[i][j]+=a.a[i][k]*b.a[k][j];
			}
			c.a[i][j]%=mod; 
		}
	}c.sz=n;
	return c;
}
mat operator ^ (mat a,int b){
	mat c;
	c.clear();
	int n=c.sz=a.sz;
	rep(i,0,n)c.a[i][i]=1;
	for(;b;b>>=1,a=a*a)if(b&1)c=c*a;
	return c;
}
int id[N];
int seed;
signed main(){
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	cin>>test>>T>>seed;
	while(T--){
		A.clear(),v0.clear();
		cin>>n>>q>>x>>kmax;
		rep(i,1,n)scanf("%llu",&a[i]),b[i]=a[i];
		vx[0]=a[x];
		for(int i=1;i<=22;i++){
			rep(j,1,n/2)b[j]=(b[j]+b[n-j+1])%998244353;
			for(int j=n;j>=1;j--)b[j]=b[j+1>>1]*499122177%998244353;
			vx[i]=b[x];
		}
		b[0]=0;
		int d=(n&-n)*2;
		int rx=(x-1)/d;
		if(n/d<=200)rep(i,0,n/d)v0.a[0][i]=b[i*d+1];
		rep(i,1,n){ 
			id[i]=(i-1)/d;
		}
		A.sz=v0.sz=n/d;
		if(n/d+1<=200){
			int cnt=0;
			rep(i,1,n/2){
				if(id[i]!=id[n-i+1]){
					A.a[id[i]][cnt]=499122177;
					A.a[id[n-i+1]][cnt]=499122177;
				}
				else {
					A.a[id[i]][cnt]=1;
				}
				if(i%(d>>1)==0)cnt++;
			}
		}
		int ans=0;
		rep(i,1,q){
			int k=rd(seed)%kmax;
			int nowans=0;
			if(test==3)k=min(k,22ull);
			if(k<=22){
				nowans=vx[k];
			}
			else {
				k-=22;
				nowans=(v0*(A^k)).a[0][rx];
				assert(nowans==vx[k+22]);
			}
			ans=ans^(nowans*i);
		}
		cout<<ans<<endl;
	}
}
