#include <bits/stdc++.h>
using namespace std;

const long long Mod=998244353;
const long long Inv2=(Mod+1)/2;

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
unsigned long long fpw(long long x,long long y)
{
	long long cur=x,tot=1;
	for(long long i=1;i<=y;i<<=1)
	{
		if(i&y)
			tot=cur*tot%Mod;
		cur=cur*cur%Mod;
	}
	return tot;
}
namespace Vio
{
	vector<int> res[505];
	void solve(int n,vector<int> a,int times)
	{
		res[0]=a;
		for(int i=1;i<=times;i++)
		{
			res[i].clear();
			res[i].push_back(0);
			for(int j=1;j<=n/2;j++)
			{
				res[i].push_back((res[i-1][j]+res[i-1][n+1-j])*Inv2%Mod);
				res[i].push_back((res[i-1][j]+res[i-1][n+1-j])*Inv2%Mod);
			}
//			if(i==4)
//			{
//				for(int j=1;j<=n;j++)
//					printf("%4d",res[i][j]*fpw(2,i)%Mod);
//				puts("");
//			}
		}
	}
}
struct matrix50
{
	int n,a[52][52];
	void mat0(int n0){n=n0;memset(a,0,sizeof a);}
	void mat1(int n0){mat0(n0);for(int i=1;i<=n;i++)a[i][i]=1;}
	vector<int> times(vector<int> aa)
	{
		vector<int> b(n+1);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				b[j]=(b[j]+1ll*a[j][i]*aa[i])%Mod;
		return b;
	}
};
struct matrix2
{
	int a[3][3];
	void mat1(int n0){a[1][1]=a[2][2]=1;a[1][2]=a[2][1]=0;}
	vector<int> times(vector<int> aa)
	{
		vector<int> b(3);
		for(int i=1;i<=2;i++)
			for(int j=1;j<=2;j++)
				b[j]=(b[j]+1ll*a[j][i]*aa[i])%Mod;
		return b;
	}
};
matrix50 operator * (matrix50 x,matrix50 y)
{
	matrix50 ans;
	ans.mat0(x.n);
	for(int k=1;k<=x.n;k++)
		for(int i=1;i<=x.n;i++)
			for(int j=1;j<=x.n;j++)
				ans.a[i][j]=(ans.a[i][j]+1ll*x.a[i][k]*y.a[k][j])%Mod;
	return ans;
}
matrix2 operator * (matrix2 x,matrix2 y)
{
	matrix2 ans;
	ans.mat1(2);
	for(int k=1;k<=2;k++)
		for(int i=1;i<=2;i++)
			for(int j=1;j<=2;j++)
				ans.a[i][j]=(ans.a[i][j]+1ll*x.a[i][k]*y.a[k][j])%Mod;
	return ans;
}
matrix50 matfpw(matrix50 x,long long y)
{
	auto ans=x,cur=x;
	ans.mat1(x.n);
	for(long long i=1;i<=y;i<<=1)
	{
		if(i&y)
			ans=ans*cur;
		cur=cur*cur;
	}
	return ans;
}
matrix50 trans;
matrix2 tr[64];
vector<int> a20;
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,RES=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<=2)
			Vio::solve(n,a,k_max);
		if(test==3)
			Vio::solve(n,a,20);
		if(test==4)
		{
			trans.mat0(n);
			for(int i=1;i<=n/2;i++)
			{
				trans.a[i][i*2-1]=trans.a[i][i*2]=Inv2;
				trans.a[n+1-i][i*2-1]=trans.a[n+1-i][i*2]=Inv2;
			}
		}
		if(test==7)
		{
			Vio::solve(n,a,20);
			a20={0,Vio::res[20][1],Vio::res[20][90000]};
			tr[0].a[1][1]=tr[0].a[1][2]=Inv2;tr[0].a[2][1]=1;tr[0].a[2][2]=0;
			for(int i=1;(1ll<<i)<=1e18;i++)
				tr[i]=tr[i-1]*tr[i-1];
		}
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			//long long k=i;
			//long long prevRES=RES;
			if(test<=2 || ((test==3 || test==7) && k<=20) )
				RES^=1ll*i*Vio::res[k][x];
			else if(test==3 && k>20)
				RES^=1ll*i*Vio::res[20][x];
			else if(test==4)
			{
				//printf("%d\n",matfpw(trans,k).times(a)[x]);
				RES^=1ll*i*matfpw(trans,k).times(a)[x];
			}
			else if(test==7)
			{
				matrix2 tmp;
				tmp.mat1(2);
				for(int i=0;(1<<i)<=1e18;i++)
					if(k&(1<<i))
						tmp=tmp*tr[i];
				if(x>65536)
					RES^=1ll*i*tmp.times(a20)[2];
				else
					RES^=1ll*i*tmp.times(a20)[1];
			}
			//printf("k=%lld Ans=%llu\n",k,(prevRES^RES)/i*1ll*fpw(2,k)%Mod);
		}
		printf("%llu\n",RES);
	}
	return 0;
}
