#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=998244353,N=2000005,L=505,Inv=M/2+1;
int test,T,n,q,x,a[24][N],b[L][L];
ll k_max;
unsigned long long rd(unsigned long long &x){
	x^=(x<<13);
	x^=(x>>7);
	x^=(x<<17);
	return x;
}
int main(){
	int test,T;
	unsigned long long seed;
	scanf("%d%d%llu", &test,&T,&seed);
	while (T--){
		scanf("%d%d%d%lld",&n,&q,&x,&k_max);
		for (int i=1;i<=n;i++)scanf("%d",&a[0][i]);
		if (test==3)k_max=22;
		for (int i=1;i<=k_max;i++)
			for (int j=1;j<=n;j++)a[i][j]=(ll)(a[i-1][(j+1)/2]+a[i-1][n-(j+1)/2+1])*Inv%M;
		if (test==1){
			for (int j=0;j<=n;j++)b[0][j]=a[0][j];
			for (int i=1;i<=k_max;i++)
				for (int j=1;j<=n;j++)a[i][j]=(ll)(a[i-1][(j+1)/2]+a[i-1][n-(j+1)/2+1])*Inv%M;
		}
		ll S=0;
		for (int i=1;i<=q;i++){
			long long k=rd(seed)%k_max;
			k=min(k,k_max);
			if (test!=1)S^=(ll)a[min(k_max,k)][x]*i;
			else S^=(ll)b[k][x]*i;
		}
		printf("%lld\n",S);
	}
}
