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

unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
int n, q, x;
long long k_max;

const long long p = 998244353;
const long long inv2 = 499122177;
struct matrix{
	int r, c;
	long long val[200][200];
	matrix operator * (matrix T){
		matrix res; res.r = r, res.c = T.c;
		for(int i = 1; i <= res.r; i++)
			for(int j = 1; j <= res.c; j++){
				res.val[i][j] = 0;
				for(int k = 1; k <= c; k++)
					res.val[i][j] = (res.val[i][j] + val[i][k] * T.val[k][j]) % p;
			}
		return res;
	}
}M[61], B;

vector<int> a;
vector<long long> at;
long long lowbit(long long x){ return x & (-x); }
long long special_1(long long k, long long x){
	B.r = n, B.c = 1;
	memset(B.val, 0, sizeof(B.val));
	for(int i = 1; i <= n; i++)
		B.val[i][1] = a[i];
	for(long long i = 0; (1<<i) <= k; i++)
		if((1<<i) & k) B = M[i] * B;
//	for(int i = 1; i <= n; i++) printf("%-12lld", B.val[i][1]); printf("\n");
	return B.val[x][1];
}
long long special_2(long long k, long long x){
	at.resize(n+1);
	for(int i = 1; i <= n; i++) at[i] = a[i];
	k = min(k, (long long)(log(k)/log(2)+3));
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= n; j++) at[j] += at[n-j+1];
		for(int j = n; j >= 1; j--) at[j] = at[(j+1)/2] * inv2 % p;
	}
//	for(int i = 1; i <= n; i++) printf("%-12lld", at[i]); printf("\n");
	return at[x];
}

long long lastans = 0;
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 ++) {
//		printf("cas=%d test=%d\n", Case, test);
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		
		M[0].r = n, M[0].c = n;
		memset(M[0].val, 0, sizeof(M[0].val));
		for(int i = 1; i <= n/2; i++){
			M[0].val[i*2-1][i] = M[0].val[i*2-1][n-i+1] = inv2;
			M[0].val[i*2][i] = M[0].val[i*2][n-i+1] = inv2;
		}
		for(long long i = 1; (1<<i) < k_max; i++)
			M[i] = M[i-1]*M[i-1];
/*			
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%-12lld", M[1].val[i][j]);
			printf("\n");
		}*/
			
		a.resize(n+1);
		for(int i = 1; i <= n; i ++) {
			scanf("%d", &a[i]);
		}
		lastans = 0;
		for(int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			if(test == 0 || test == 1 || test == 4 || test == 8 || test == 9){
				long long res = special_1(k, x);
//				printf("%lld\n", res);
				lastans = lastans ^ (res*i);
			}
			if(test == 3){
				long long res = special_2(k, x);
//				printf("%lld\n", res);
				lastans = lastans ^ (res*i);
			}
		}
		printf("%lld\n", lastans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
