#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int P=998244353;
const int I2=499122177;
int test,T;
ull seed;
ull rd(ull &x){
	x^=(x<<13);
	x^=(x>>7);
	x^=(x<<17);
	return x;
}
namespace Sub1{
	void solve(){
		for(int Case=1;Case<=T;++Case){
			int n,q,x;
			long long k_max,ans=0;
			scanf("%d%d%d%lld",&n,&q,&x,&k_max);
			vector<int>a(n+1);
			for(int i=1;i<=n;++i)
				scanf("%d",&a[i]);
			vector<vector<int> >b(k_max+1);
			b[0]=a;
			for(int i=1;i<=k_max;++i){
				b[i].push_back(0);
				for(int j=1;j<=n/2;++j){
					int t=1ll*(b[i-1][j]+b[i-1][n-j+1])*I2%P;
					b[i].push_back(t);
					b[i].push_back(t);
				}
			}
			for(int i=1;i<=q;++i){
				long long k=rd(seed)%k_max;
				ans^=1ll*b[k][x]*i;
			}
			printf("%lld\n",ans);
		}
	}
}
namespace Sub2{
	void solve(){
		for(int Case=1;Case<=T;++Case){
			int n,q,x;
			long long k_max,ans=0;
			scanf("%d%d%d%lld",&n,&q,&x,&k_max);
			vector<int>a(n+1);
			for(int i=1;i<=n;++i)
				scanf("%d",&a[i]);
			int lg=0;
			while((1<<lg)<n)
				++lg;
			vector<vector<int> >b(lg+1);
			b[0]=a;
			for(int i=1;i<=lg;++i){
				b[i].push_back(0);
				for(int j=1;j<=n/2;++j){
					int t=1ll*(b[i-1][j]+b[i-1][n-j+1])*I2%P;
					b[i].push_back(t);
					b[i].push_back(t);
				}
			}
			for(int i=1;i<=q;++i){
				long long k=rd(seed)%k_max;
				if(k>lg)
					k=lg;
				ans^=1ll*b[k][x]*i;
			}
			printf("%lld\n",ans);
		}
	}
}
int calc(int a,long long b,int p){
	int res=1;
	while(b){
		if(b&1)
			res=1ll*res*a%p;
		a=1ll*a*a%p;
		b>>=1;
	}
	return res;
}
namespace Sub3{
	const int N=5e2+7;
	int H[N][N];
	void solve(){
		for(int Case=1;Case<=T;++Case){
			int n,q,p;
			long long k_max,ans=0;
			scanf("%d%d%d%lld",&n,&q,&p,&k_max);
			vector<int>a(n+1);
			for(int i=1;i<=n;++i)
				scanf("%d",&a[i]);
			for(int i=1;i<=q;++i){
				long long k=rd(seed)%k_max;
				int x=calc(I2,k,P);
				int s=calc(2,k,P);
				int w=calc(2,k,n*2);
				int y=(1ll*s*calc(n*2,P-2,P)%P-1ll*w*calc(n*2,P-2,P)%P+P)%P;
				int cur=1,f=1;
				for(int j=1;j<=n;++j){
					for(int l=1;l<=n;++l)
						H[j][l]=2ll*y*x%P;
					int z=w;
					while(z){
						(H[j][cur]+=x)%=P;
						if(cur==n&&f==1)
							f=-1;
						else if(cur==1&&f==-1)
							f=1;
						else
							cur+=f;
						--z;
					}
				}
				int res=0;
				for(int l=1;l<=n;++l)
					res=(res+1ll*a[l]*H[l][p])%P;
				ans^=1ll*res*i;
			}
			printf("%lld\n",ans);
		}
	}
}
int main(){
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	scanf("%d%d%llu",&test,&T,&seed);
	if(test<=2)
		Sub1::solve();
	else if(test==3)
		Sub2::solve();
	else if(test<=9&&test!=7)
		Sub3::solve();
	return 0;
}