#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
const int N=2e6+10;
unsigned long long rd(unsigned long long &x) 
{
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
int ksm(int a,int l)
{
	int res=1;
	for(;l;l>>=1,a=a*a%mod)
		if(l&1) res=res*a%mod;
	return res; 
}
int inv(int x){return ksm(x,mod-2);}
int n,k,pos;
int a[N],b[2][N];
int sub12()
{
	for(int i=1;i<=n;i++) b[0][i]=a[i];
	for(int i=1;i<=k;i++)
		for(int j=1;j<=n/2;j++)
			 b[i&1][(j<<1)-1]=b[i&1][j<<1]=b[i&1^1][j]+b[i&1^1][n-j+1]; 
	return b[k&1][pos]*inv(ksm(2,k))%mod;
}
int sub3()
{
	int res=0;
	for(int i=1;i<=n;i++) (res+=a[i])%=mod;
	return res*inv(n)%mod; 
} 
signed main() 
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	ios::sync_with_stdio(0);
	int test, T;
	unsigned long long seed;
	cin>>test>>T>>seed;
	while(T--)
	{
		int q,k_max,ans=0;
		cin>>n>>q>>pos>>k_max;
		for(int i = 1; i <= n; i ++) cin>>a[i];
		for(int i = 1; i <= q; i ++) 
		{
			k = rd(seed) % k_max;
			if(test==3) ans^=i*sub3();
			else ans^=i*sub12(); 
		}
		cout<<ans<<'\n';
	}
}
