#include <bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x) {
	x = 0;
	char ch = getchar();
	while (!isdigit(ch))
		ch = getchar();
	while (isdigit(ch))
		x = x * 10 + ch - 48, ch = getchar();
}
const int P = 998244353, inv2 = (P + 1) / 2;
inline void add(int &x, int y) {
	(x += y) >= P && (x -= P);
}
inline void sub(int &x, int y) {
	(x -= y) < 0 && (x += P);
}
inline void mul(int &x, int y) {
	x = 1ull * x * y % P;
}
inline int Add(int x, int y) {
	return add(x, y), x;
}
inline int Sub(int x, int y) {
	return sub(x, y), x;
}
inline int Mul(int x, int y) {
	return mul(x, y), x;
}
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
const int N = 2000005;
int n, q, x, a[N], b[N], res[30], ans[100][100];
long long k_max;
int main() {
	freopen("noodle_ex1.in", "r", stdin);
	int test, T;
	unsigned long long seed;
	read(test), read(T), read(seed);
	for(int Case = 1; Case <= T; ++Case) {
		read(n), read(q), read(x), read(k_max);
		for(int i = 1; i <= n; ++i) 
			read(a[i]);
//		int t = 0;
//		while (n % (1 << t) == 0)
//			++t;
//		res[0] = a[x];
//		for (int tt = 1; tt <= t; ++t) {
//			for (int i = 1; i <= n / 2; ++i)
//				add(a[i], a[n - i + 1]), mul(a[i], inv2);
//			n /= 2, x /= 2;
//			res[tt] = a[x];
//		}
//		
		for (int t = 0; t <= 100; ++t) {
//			printf("array[%d] :: ", t);
			for (int i = 1; i <= n; ++i)
//				printf("%d%c", a[i], " \n"[i == n]);
				ans[t][i] = a[i];
			for (int i = 1; i <= n / 2; ++i)
				b[i] = Add(a[i], a[n - i + 1]);
			for (int i = 1; i <= n / 2; ++i)
				a[2 * i - 1] = a[2 * i] = Mul(b[i], inv2);
		}
		for(int i = 1; i <= q; ++i) {
			long long k = rd(seed) % k_max;
			printf("%d\n", ans[k][x]);
		}
	}
}
