#include <bits/stdc++.h>
#define I inline
#define RI register int
#define rep(i,a,b) for(RI i=a;i<=b;++i)
#define dow(i,a,b) for(RI i=a;i>=b;--i)
using namespace std;

const int N=2e6+5,mo=998244353,Inv2=499122177;

I int add(int a,int b){ return a+b>=mo?a+b-mo:a+b; }
I int mul(int a,int b){ return 1ll*a*b%mo; }

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}

int n,q,x;

struct Matrix{
	int a[155][155];
	Matrix(){
		rep(i,1,150) rep(j,1,150) a[i][j]=0;
	}
};
Matrix mul(Matrix a,Matrix b){
	Matrix c;
	rep(k,1,n) rep(i,1,n) rep(j,1,n) 
		c.a[i][j]=add(c.a[i][j],mul(a.a[i][k],b.a[k][j]));
	return c;
}
long long ans;

int b[N];

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 ++) {
		long long k_max;ans=0;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		if(n==98304) k_max=20;
		if(n<=500&&q<=500&&k_max<=500||k_max<=40){
			int a[n+1][k_max+1];
			for(int i = 1; i <= n; i ++) {
				scanf("%d", &a[i][0]);
			}
			rep(i,1,k_max){
				rep(j,1,n/2) b[j]=a[j][i-1];
				rep(j,n/2+1,n) b[n-j+1]=add(b[n-j+1],a[j][i-1]);
				rep(j,1,n/2) a[j<<1][i]=a[(j<<1)-1][i]=mul(b[j],Inv2);
			}
			ans=0;
			for(int i = 1; i <= q; i ++) {
				long long k = rd(seed) % k_max;
				ans^=1ll*a[x][k]*i;
			}
			printf("%lld\n",ans);
		} else {
			int a[n+5];
			for(int i = 1; i <= n; i ++) {
				scanf("%d", &a[i]);
			}
			RI sum=0;
			for(int j=1;j<=q;++j){
				sum=0;
				long long k = rd(seed) % k_max;
				Matrix now,pw;
				rep(i,1,n) now.a[i][i]=1;
				rep(i,1,n){
					RI x=i+1>>1;
					pw.a[i][x]=pw.a[i][n-x+1]=Inv2;
				}
				while(k){
					if(k&1) now=mul(now,pw);
					pw=mul(pw,pw);
					k>>=1;
				}
				rep(i,1,n) sum=add(sum,mul(a[i],now.a[x][i]));
				ans^=1ll*sum*j;
			}             
			printf("%d\n",ans);
		}
	}
}