// 特征多项式 & Cayley-Hamiton / 对角化
// 然而没有推出来
// 因为 n>=4 似乎就不可对角化，而且特征多项式也没有明显规律

// 2:f(x)=x(x-1)
// 4:f(x)=x^3(x-1)
// 6:f(x)=x^4(x+1/2)(x-1)
// 8:f(x)=x^7(x-1)

#include <bits/stdc++.h>
typedef unsigned uint;
typedef unsigned long long ullt;typedef long long llt;
typedef bool bol;typedef char chr;typedef void voi;
const ullt Mod=998244353;
struct modint
{
	ullt v;
	modint():v(){}
	modint(ullt v):v(v%Mod){}
	friend modint operator+(modint a,modint b){return a()+b();}
	friend modint operator-(modint a,modint b){return a()+Mod-b();}
	friend modint operator*(modint a,modint b){return a()*b();}
	inline ullt&operator()(){return v;}
	modint&operator+=(modint v){return*this=*this+v;}
	voi read(){scanf("%llu",&v),v%=Mod;}
	voi println(){printf("%llu\n",v);}
};
uint N;
struct Mat
{
	modint A[205][205];
	modint*operator[](uint n){return A[n];}
	voi println(){for(uint i=0;i<N;i++,puts(""))for(uint j=0;j<N;j++)printf("%llu ",A[i][j]());}
	friend Mat operator*(Mat a,Mat b){
		Mat ans;
		for(uint i=0;i<N;i++)for(uint j=0;j<N;j++)for(uint k=0;k<N;k++)
			ans[i][k]+=a[i][j]*b[j][k];
		return ans;
	}
	friend Mat Pow(Mat base,ullt index)
	{
		Mat ans;
		for(uint i=0;i<N;i++)ans[i][i]=1;
		while(index)
		{
			if(index&1)ans=ans*base;
			base=base*base;index>>=1;
		}
		return ans;
	}
};
inline ullt rd(ullt &x){x^=(x<<13),x^=(x>>7),x^=(x<<17);return x;}
modint A[2000005];
int main()
{
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	uint op,T;ullt seed;
	scanf("%u%u%llu",&op,&T,&seed);
	modint inv2=(Mod+1)/2;
	while(T--){
		uint n,q,x;ullt k_max;
		scanf("%u%u%u%llu",&n,&q,&x,&k_max),x--;
		for(uint i=0;i<n;i++)A[i].read();
		N=n;
		ullt ans=0;
		if(op<=2||(k_max<=1000000&&n*k_max<=3000000))
		{
			std::vector<std::vector<modint> >QwQ(k_max,std::vector<modint>(n));
			for(uint i=0;i<n;i++)QwQ[0][i]=A[i];
			for(uint i=1;i<k_max;i++)
			{
				for(uint j=0;j<n/2;j++)QwQ[i][j<<1]+=QwQ[i-1][j]*inv2,QwQ[i][j<<1|1]+=QwQ[i-1][j]*inv2;
				for(uint j=0;j<n/2;j++)QwQ[i][j<<1]+=QwQ[i-1][n-j-1]*inv2,QwQ[i][j<<1|1]+=QwQ[i-1][n-j-1]*inv2;
			}
			for(uint t=1;t<=q;t++){
				ullt k=rd(seed)%k_max;
				modint v=QwQ[k][x];
				ans^=v()*t;
			}
		}
		else if(op==3)
		{
			std::vector<std::vector<modint> >QwQ(22,std::vector<modint>(n));
			for(uint i=0;i<n;i++)QwQ[0][i]=A[i];
			for(uint i=1;i<=21;i++)
			{
				for(uint j=0;j<n/2;j++)QwQ[i][j<<1]+=QwQ[i-1][j]*inv2,QwQ[i][j<<1|1]+=QwQ[i-1][j]*inv2;
				for(uint j=0;j<n/2;j++)QwQ[i][j<<1]+=QwQ[i-1][n-j-1]*inv2,QwQ[i][j<<1|1]+=QwQ[i-1][n-j-1]*inv2;
			}
			for(uint t=1;t<=q;t++){
				ullt k=rd(seed)%k_max;
				if(k>=22)k=21;
				modint v=QwQ[k][x];
				ans^=v()*t;
			}
		}
		else
		{
			Mat B;
			for(uint i=0;i<n/2;i++)B[i][i<<1]=B[i][i<<1|1]=inv2;
			for(uint i=0;i<n/2;i++)B[n-i-1][i<<1]=B[n-i-1][i<<1|1]=inv2;
			for(uint t=1;t<=q;t++){
				ullt k=rd(seed)%k_max;
				modint v;
				Mat C=Pow(B,k);
				for(uint i=0;i<n;i++)v+=A[i]*C[i][x];
				ans^=v()*t;
			}
		}
		printf("%llu\n",ans);
	}
	return 0;
}

