#include<bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
long long b[1000001],ans;
unsigned long long rd(unsigned long long &x)
{
	x^=(x<<13);
	x^=(x>>7);
	x^=(x<<17);
	return 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++)
	{
		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]);
		if (test==3)
		{
			b[0]=a[x];
			long long tk=log2(n);
			for (int i=1;i<=tk;i++)
			{
				for (int t=1;t<=n/2;t++)
					a[t]=(a[t]+a[n-t+1])*499122177ll%MOD;
				for (int t=n;t>=1;t--)
					a[t]=a[(t+1)/2];
				b[i]=a[x];
			}
			for (long long i=1;i<=q;i++)
			{
				long long k=rd(seed)%k_max;
				ans=ans^(b[min(tk,k)]*i%MOD);
			}
			printf("%lld\n",ans);
		}
		else 
		{
			b[0]=a[x];
			for (int i=1;i<=k_max;i++)
			{
				for (int t=1;t<=n/2;t++)
					a[t]=(a[t]+a[n-t+1])*499122177ll%MOD;
				for (int t=n;t>=1;t--)
					a[t]=a[(t+1)/2];
				b[i]=a[x];
			}
			for (long long i=1;i<=q;i++)
			{
				long long k=rd(seed)%k_max;
				ans=ans^(b[k]*i%MOD);
			}
			printf("%lld\n",ans);
		}
	}
	return 0;
}
