#include <bits/stdc++.h>
#define rep(i, l, r) for(int i=l, _=r; i<=_; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read() {
	ll res=0; bool k=1; char ch;
	while(!isdigit(ch=getchar())) k=ch^45;
	do res=res*10+(ch&15); while(isdigit(ch=getchar()));
	return k? res: -res;
}
bool Mbe;
const int mN=2e6+9, mod=998244353;
int n, q, x, a[mN], k_max, test, T;
ll k;

ull seed;
ull rd(ull &x=seed) {
	x^=x<<13, x^=x>>7, x^=x<<17;
//	printf("k = %llu\n", seed%k_max);
	return x;
}

namespace solve1 {
	const int mK=500+9;
	int ans[mK], b[mN];
	void init() {
		ans[0]=a[x];
		rep(__, 1, k_max-1) {
			rep(i, 1, n/2) b[i]=a[i]+a[n-i+1];
			rep(i, 1, n) a[i]=499122177ll*b[(i+1)/2]%mod;
			ans[__]=a[x];
		}
//		printf("ans:");
//		rep(i, 0, k_max-1) printf(" %d", ans[i]);
//		puts("");
	}
	void main() {
		init();
		ull res=0;
		rep(__, 1, q) res^=(ull) __*ans[rd()%k_max];
		printf("%llu\n", res);
	}
}
namespace solve2 {
	const int mK=20+9;
	int ans[mK], b[mN];
	void init() {
		ans[0]=a[x];
		rep(__, 1, 20) {
			rep(i, 1, n/2) b[i]=a[i]+a[n-i+1];
			rep(i, 1, n) a[i]=499122177ll*b[(i+1)/2]%mod;
			ans[__]=a[x];
		}
	}
	void main() {
		init();
		ull res=0;
		rep(__, 1, q) res^=(ull) __*ans[min(rd()%k_max, 20ull)];
		printf("%llu\n", res);
	}
}
namespace solve3 {
	const int mN=150+9, mD=64;
	struct Matrix {
		int n, m, a[mN][mN];
		Matrix (int n_=::n, int m_=::n): n(n_), m(m_) {
			rep(i, 0, n-1) rep(j, 0, m-1) a[i][j]=0;
		}
		Matrix operator * (Matrix m2) {
			Matrix res(n, m2.m);
			rep(i, 0, n-1) rep(j, 0, m2.m-1) rep(k, 0, m-1)
				res.a[i][j]=(res.a[i][j]+(ll) a[i][k]*m2.a[k][j])%mod;
			return res;
		}
	} p[mD];
	void init() {
		p[0]=Matrix(n, n);
		rep(i, 0, n-1) p[0].a[i/2][i]=p[0].a[n-1-i/2][i]=499122177;
		rep(j, 1, mD-1) p[j]=p[j-1]*p[j-1];
	}
	void main() {
		init();
		ull res=0;
		rep(__, 1, q) {
			k=rd()%k_max;
			Matrix now(1, n);
			rep(i, 1, n) now.a[0][i-1]=a[i];
			for(int t=mD-1; t>=0; --t) if(k>>t&1) now=now*p[t];
//			printf("ans %lld = %d\n", k, now.a[0][x-1]);
			res^=(ull) __*now.a[0][x-1];
		}
		printf("%llu\n", res);
	}
}

bool Men;
int main() {
//	cerr<<"memory: "<<(&Men-&Mbe>>20)<<" MB"<<endl;
	freopen("noodle.in", "r", stdin);
	freopen("noodle.out", "w", stdout);
	test=read(), T=read(), seed=read();
	while(T--) {
		n=read(), q=read(), x=read(), k_max=read();
		rep(i, 1, n) a[i]=read();
		switch(test) {
			case 1: case 2: solve1::main(); break;
			case 3: solve2::main(); break;
			case 4: case 5: case 6: solve3::main(); break;
		}
	}
	return 0;
}
