#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mu=998244353,N=2e6+5,inv2=(mu+1)/2;
int n,q,x,a[N],f[N],tans[N];
void reduce(int &x){
	x+=x>>31&mu;
}
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
void solve(int k){
	tans[0]=a[x];
	for (int j=1;j<=k;j++){
		for (int i=1;i<=n/2;i++)
			f[i]=((ll)a[i]+a[n-i+1])*inv2%mu;
		for (int i=1;i<=n;i+=2)
			a[i]=a[i+1]=f[(i+1)/2];
		tans[j]=a[x];
	}
}
struct Match{
	int a[155][155];
	void mem(){
		memset(a,0,sizeof(a));
	}
	friend Match operator *(Match a,Match b){
		Match t;
		t.mem();
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)
				for (int k=1;k<=n;k++)
					reduce(t.a[i][j]+=(ll)a.a[i][k]*b.a[k][j]%mu-mu);
		return t;
	}
};
struct note{
	int a[155];
	void mem(){
		memset(a,0,sizeof(a));
	}
	friend note operator *(note a,Match b){
		note t;
		t.mem();
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)
				reduce(t.a[j]+=(ll)a.a[i]*b.a[i][j]%mu-mu);
		return t;
	}
};
int solve2(ll k){
	Match f;
	f.mem();
	for (int i=1,j=1;i<=n;i+=2,j++)
		f.a[j][i+1]=f.a[j][i]=f.a[n-j+1][i]=f.a[n-j+1][i+1]=inv2;
	note ans;ans.mem();
	for (int i=1;i<=n;i++) ans.a[i]=a[i];
	for (;k;k>>=1,f=f*f)
		if (k&1) ans=ans*f;
	return ans.a[x]; 
}
int main() {
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	int test, T;
	unsigned long long seed;
	scanf("%d%d%llu", &test, &T, &seed);
	for(int Case = 1; Case <= T; Case ++) {
		long long k_max,Ans=0;
		int ret;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		for (int i=1;i<=n;i++) scanf("%d",&a[i]);
		if (test<3) solve(k_max);
		else if (test==3) solve(22);
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			if (test==3) k=std::min(k,22ll);
			if (test<=3) ret=tans[k];
			else if (test<=6) ret=solve2(k);
			Ans^=(ll)ret*i;
		}
		printf("%lld\n",Ans);
	}
}
