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

using ll = long long;
using llu = long long unsigned;
const int N = 2e6+5, md = 998244353, INV2 = 499122177;
int n, q, x;
int r_a[N], r_b[N];
ll ans, k_max;
llu seed;
vector<int> ra, a, b;

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

namespace st3 {
	void MakeNoodle() {
		b.resize(n);
		for(int i = 0; i < n/2; ++i) {
			b[2*i] = b[2*i+1] = 1ll*(a[i] + a[n-i-1])*INV2%md;
		}
		swap(a, b);
	}
}

void Debug() {
	for(int i = 0; i < n; ++i) {
		clog<<setw(10)<<a[i];
	}
	clog<<endl;
}

namespace st6 {
	struct Mat {
		struct Zero_t {};
		struct Ident_t {};
		int w, h;
		vector<int> dat;

		// Mat(int w, int h, vector<int> &&v): w(w), h(h), dat(v) {}
		Mat(int w, int h, const vector<int> &v): w(w), h(h), dat(v) {}
		Mat(int w, int h, Zero_t cons): w(w), h(h), dat(w*h) {}
		Mat(int w, int h, Ident_t cons = Ident_t{}): w(w), h(h), dat(w*h) {
			for(int i = 0; i < h && i < w; ++i)
				dat[i*w + i] = 1;
		}

		Mat operator*(const Mat &o) {
			Mat res(w, o.h, Zero_t{});
			for(int i = 0; i < o.h; ++i)
				for(int j = 0; j < w; ++j)
					for(int k = 0; k < o.w; ++k) {
						res.dat[i*w + j] = (res.dat[i*w + j]
											+ 1ll*o.dat[i*o.w + k]*dat[k*w + j])%md;
					}
			return res;
		}
	};
	Mat GetM() {
		Mat res(n, n, Mat::Zero_t{});
		for(int i = 0; i < n/2; ++i) {
			res.dat[res.w*i + 2*i] = res.dat[res.w*i + 2*i+1]
				= res.dat[res.w*(n-i-1) + 2*i] = res.dat[res.w*(n-i-1) + 2*i+1]
				= INV2;
		}
		return res;
	}
	Mat power(const Mat &b, ll ex) {
		Mat res(n, n), f = b;
		while(ex) {
			if(ex & 1) res = f*res;
			ex >>= 1;
			f = f*f;
		}
		return res;
	}
	void work() {
		// clog<<"# working as st6. "<<endl;
		Mat M = move(GetM());
		for(int i = 1; i <= q; i ++) {
			ll k = rd(seed) % k_max;
			Mat B = power(M, k)*Mat(n, 1, ra);
			ans ^= 1ll*B.dat[x-1]*i;
		}
	}
}

int main() {
	ios::sync_with_stdio(0);

	int test, T;

	cin>>test>>T>>seed;
	a.reserve(N), b.reserve(N);
	for(int Case = 1; Case <= T; Case++) {
		ans = 0;
		cin>>n>>q>>x>>k_max;
		ra.resize(n);
		for(int i = 0; i < n; i ++) {
			cin>>ra[i];
		}
		
		if((test & 31) <= 3) {
			for(int i = 1; i <= q; i ++) {
				ll k = rd(seed) % k_max;
				a = ra;
				if((test & 31) == 3)
					k = min(k, 22ll);
				for(int j = 0; j < k; ++j) {
					st3::MakeNoodle();
				}
				ans ^= 1ll*a[x-1]*i;
			}
		} else {
			st6::work();
		}
		cout<<ans<<"\n";
	}
	return 0;
}
