#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("noodle.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]),a[i]=i==X,b[i]=i==X;
		int tt=0;
		vector<int>ans={num[X]};
		while(SZ(ans)<=k_max){
			deal(a);
			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);
			}
			bool flg=1;
			rep(i,2,n){
				flg&=su(a[i],a[i-1])==su(b[i],b[i-1]);
			}
			++tt;
			if(flg)break;
		}
		int pw_tt=po(2,tt);
		vector<int>w(tt+1);
		rep(i,1,tt){
			deal(b);
			int ret=0;
			rep(i,1,n){
				uad(ret,mu(num[i],b[i]));
			}
			w[i]=su(ret,mu(ans[SZ(ans)-tt+i-1],pw_tt));
		}
		//D("tt=%d\n",tt);
		long long res=0;
		rep(i,1,Q){
			long long k=gen(seed)%k_max;
			if(k<SZ(ans)){
				res^=1LL*ans[k]*po((P+1)>>1,k)%P*i;
			}else{
				long long k_=k%tt;
				k_=k_+(SZ(ans)-1-k_)/tt*tt;
				//assert(k_<SZ(ans)&&k_+tt>=SZ(ans));
				long long cnt=(k-k_)/tt;
				int coef=w[k_+tt-SZ(ans)+1];
				int ret=ans[k_];
				//D("cnt=%lld\n",cnt);
				/*rep(i,1,cnt){
					ret=(1LL*ret*pw_tt+coef)%P;
				}*/
				if(pw_tt==1){
					uad(ret,mu(cnt%P,coef));
				}else{
					ret=mu(ret,po(pw_tt,cnt));
					uad(ret,mu(coef,mu(su(1,po(pw_tt,cnt)),po(su(1,pw_tt),P-2))));
				}
				res^=1LL*ret*po((P+1)>>1,k)%P*i;
			}
		}
		printf("%lld\n",res);
	}
	return 0;
}
