#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define each(x,v) for(auto&x:v)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
using namespace std;
template<class T>
void rd(T&x){
	int f=0,c;
	while(!isdigit(c=getchar()))f^=!(c^45);
	x=(c&15);
	while(isdigit(c=getchar()))x=x*10+(c&15);
	if(f)x=-x;
}
const int P=998244353;
inline int ad(int x,int y){return x+y>=P?x+y-P:x+y;}
inline int su(int x,int y){return x-y<0?x-y+P:x-y;}
inline int mu(int x,int y){return 1ULL*x*y%P;}
inline void uad(int&x,int y){(x+=y)>=P&&(x-=P);}
inline void usu(int&x,int y){(x-=y)<0&&(x+=P);}
inline int po(int a,long long b){
	int c=1;
	while(b){
		if(b&1)c=1LL*c*a%P;
		if(b>>=1)a=1LL*a*a%P;
	}
	return c;
}
const int N=2000005;
int n,Q,X,num[N],a[N],b[N];
unsigned long long gen(unsigned long long&x){
	x^=(x<<13);
	x^=(x>>7);
	x^=(x<<17);
	return x;
}
void deal(int *a){
	static int tmp[N];
	rep(i,1,n){
		tmp[i]=a[i];
		a[i]=0;
	}
	rep(i,1,n){
		uad(a[(i+1)/2],tmp[i]);
		uad(a[n+1-(i+1)/2],tmp[i]);
	}
}
int main(){
	freopen("noodle.in","r",stdin);
	freopen("noodle0.out","w",stdout);
	int test,T;
	unsigned long long seed;
	cin>>test>>T>>seed;
	rep(tc,1,T){
		long long k_max;
		cin>>n>>Q>>X>>k_max;
		rep(i,1,n)rd(num[i]);
		vector<int>ans={num[X]};
		fill(b+1,b+n+1,0);
		b[X]=1;
		long long res=0;
		rep(i,1,Q){
			long long k=gen(seed)%k_max;
			while(k>=SZ(ans)){
				deal(b);
				{
					int ret=0;
					rep(i,1,n){
						uad(ret,mu(num[i],b[i]));
					}
					ans.pb(ret);
				}
				deal(b);
				{
					int ret=0;
					rep(i,1,n){
						uad(ret,mu(num[i],b[i]));
					}
					ans.pb(ret);
				}
			}
			res^=1LL*ans[k]*po((P+1)>>1,k)%P*i;
		}
		printf("%lld\n",res);
	}
	return 0;
}
