#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,q,x,k_max,km,ans[510],p=998244353,d2=499122177;
ll a[2000010],b[2000010];
ll anss;

ll readd()
{
	ll x=0;
	char c=' ';
	while (c<'0'||c>'9')
		c=getchar();
	while (c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}

struct jz{
	ll a[160][160];
};

jz jc(jz a,jz b)
{
	jz c;
	memset(c.a,0,sizeof c.a);
	for (ll i=1;i<=n;i++)
		for (ll j=1;j<=n;j++)
			for (ll k=1;k<=n;k++)
				c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j])%p;
	return c;
}

ll sol(ll k)
{
	jz aa,b;
	memset(aa.a,0,sizeof aa.a);
	memset(b.a,0,sizeof b.a);
	for (ll i=1;i<=n;i++)
	{
		aa.a[i][(i+1)/2]=d2;
		aa.a[i][n-((i+1)/2)+1]=d2;
		b.a[i][i]=1;
	}
	while (k>0)
	{
		if (k%2==1)
			b=jc(aa,b);
		aa=jc(aa,aa);
		k/=2;
	}
	ll ansk=0;
	for (ll i=1;i<=n;i++)
		ansk=(ansk+b.a[x][i]*a[i])%p;
	return ansk;	
}

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 ++) 
	{
		scanf("%lld%lld%lld%lld", &n, &q, &x, &k_max);
		for(int i = 1; i <= n; i ++) 
			a[i]=readd(),b[i]=a[i];
		if (test>3)
		{
			anss=0;
			for(ll i = 1; i <= q; i ++) 
			{
				long long k = rd(seed) % k_max;
				anss=anss^(sol(k)*i);
			}
			printf("%lld\n",anss);
		}
		else
		{
			ans[0]=b[x];
			km=k_max;
			if (test==3)
				km=61;
			for(int i=1;i<=km;i++)
			{
				for (int j=1;j<=n/2;j++)
					b[j]=b[j]+b[n-j+1];
				for (int j=n;j>=1;j--)
					b[j]=(b[(j+1)/2]*d2)%p;
				ans[i]=b[x];
			}
			anss=0;
			for(int i = 1; i <= q; i ++) 
			{
				long long k = rd(seed) % k_max;
				if (test==3&&k>=61)
					k=61;
				anss=anss^(ans[k]*i);
			}
			printf("%lld\n",anss);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
