#include<bits/stdc++.h>
using namespace std;
#define N 2000200
typedef long long ll;
typedef unsigned long long ull;
const int mod=998244353;
const int inv2=(mod+1)/2;
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
int myh;
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
ull seed;
int n,Q,P,a[N];
ll kmax;
struct Matrix{
	vector<vector<int> > g;
	void init(int len){
		g.resize(len+1);
		for(int i=1;i<=len;++i){
			g[i]=vector<int>(len+1);
		}
	}
	friend Matrix operator * (const Matrix &a,const Matrix &b){
		Matrix c;
		int n=(int)a.g.size()-1;
		c.init(n);
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				for(int k=1;k<=n;++k){
					c.g[i][j]=(c.g[i][j]+1LL*a.g[i][k]*b.g[k][j])%mod;
				}
			}
		}
		return c;
	}
}s,A[65];
struct Vector{
	vector<int> g;
	void init(int len){
		g.resize(len+1);
	}
	friend Vector operator * (const Vector &a,const Matrix &b){
		Vector c;
		int n=(int)a.g.size()-1;
		c.init(n);
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				c.g[i]=(c.g[i]+1LL*a.g[j]*b.g[j][i])%mod;
			}
		}
		return c;
	}
};
int calc(ll k){
	Vector t;
	t.init(n);
	for(int i=1;i<=n;++i){
		t.g[i]=a[i];
	}
	for(int i=60;i>=0;--i){
		if(k>>i&1){
			t=t*A[i];
		}
	}
	return t.g[P];
}
void Solve(){
	cin>>n>>Q>>P>>kmax;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	if(myh<=3){
		ll Ans=0;
		static int ans[2333];
		int W=myh==3?22:kmax;
		ans[0]=a[P];
		for(int zz=1;zz<=W;++zz){
			for(int i=1;i<=n/2;++i){
				a[i]=(a[i]+a[n-i+1])%mod;
			}
			for(int i=n;i>=1;--i){
				a[i]=1LL*a[(i+1)/2]*inv2%mod;
			}
			ans[zz]=a[P];
		}
		for(int e=1;e<=Q;++e){
			ll k=rd(seed)%kmax;
			Ans^=1LL*e*ans[min((ll)W,k)];
		}
		cout<<Ans<<'\n';
		return;
	}
	s.init(n);
	for(int i=1;i<=n;++i){
		int p=(i+1)/2;
		s.g[p][i]=s.g[n-p+1][i]=inv2;
	}
	A[0]=s;
	for(int i=1;i<=60;++i){
		A[i]=A[i-1]*A[i-1];
	}
	ll Ans=0;
	for(int e=1;e<=Q;++e){
		ll k=rd(seed)%kmax;
		Ans^=1LL*e*calc(k);
	}
	cout<<Ans<<'\n';
	/*
	cerr.setf(ios::fixed);
	cerr.precision(2);
	for(int zz=1;zz<=10;++zz){
		for(int i=1;i<=n/2;++i){
			_a[i]+=_a[n-i+1];
		}
		for(int i=n;i>=1;--i){
			_a[i]=_a[(i+1)/2]/2.0;
		}
		map<double,int> mp;
		int cnt=0;
		for(int i=1;i<=n;++i){
			if(!mp.count(_a[i]))mp[_a[i]]=++cnt;
			cerr<<mp[_a[i]]<<" ";
		}
		cerr<<endl;
	}
	*/
	/*
	while(Q--){
		ll k;
		
	}
	*/
}
int main(){
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>myh>>T>>seed;
	while(T--){
		Solve();
	}
	return 0;
}
