#include<bits/stdc++.h>
#define For(i,x,y) for (int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (int i=(x);i<(y);i++)
#define Dow(i,x,y) for (int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define siz(x) ((int)x.size())
#define fil(a,b) memset(a,b,sizeof a)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
	ll x=0,f=1;char c=getchar();
	while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if (c=='-') f=-1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

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

const int N = 2e6+10, mod = 998244353, mod2 = 1e9+9;
int id,n,q,x,a[N],b[N],t[N],c[N],cc[N],del[N],ss[N];
pa tr[N];
poly ans[N];
ll kmx;
inline int power(int a,ll b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod; 
	return ret;
}
inline int Mod(int x){
	return x>=mod?x-mod:x;
}

struct mat{
	int a[2][2];
	mat(){
		fil(a,0);
	}
	inline mat operator * (const mat &p)const{
		mat ret;
		For(i,0,1) For(j,0,1){
			ret.a[i][j]=(1ll*a[i][0]*p.a[0][j]+1ll*a[i][1]*p.a[1][j])%mod;
		}	
		return ret;
	}
}base;
inline mat power(mat a,ll b){
	mat ret;
	For(i,0,1) ret.a[i][i]=1;
	for (;b;b>>=1,a=a*a) if (b&1) ret=ret*a;
	return ret;
}

inline void solve(int kk){
	n=read(),q=read(),x=read(),kmx=read();
	int all=0;
	For(i,1,n) a[i]=read(),all=Mod(all+a[i]);
	if (id<=2){
		For(i,0,kmx) ans[i].resize(n+1);
		For(i,1,n) ans[0][i]=a[i];
		For(i,1,kmx){
			For(j,1,n/2) b[2*j]=b[2*j-1]=1ll*(a[j]+a[n-j+1])*(mod+1)/2%mod;
			For(j,1,n) ans[i][j]=a[j]=b[j]; 
		}
		ll Ans=0;
		For(i,1,q){
			ll k=rd(seed)%kmx;
			Ans^=1ll*ans[k][x]*i;
		}
		printf("%lld\n",Ans);
		return;
	}
	For(i,1,n) c[i]=0;
	c[x]=1;
	poly Ans(n+1);
	Ans[0]=a[x];
	int l=0,r=0;
	map<pa,int>vis;
	For(i,1,n){
		For(j,1,n){
			if (j<=n/2) t[j]=Mod(c[2*j]+c[2*j-1]);
				else t[j]=Mod(c[2*(n-j+1)]+c[2*(n-j+1)-1]);
		}
		For(j,1,n) Ans[i]=(Ans[i]+1ll*a[j]*t[j])%mod,c[j]=t[j];
		int h=0,h2=0;
		ss[i]=0;
		For(j,1,n){
			int tmp=(c[j]-c[1]+mod)%mod;
			ss[i]=(ss[i]+1ll*tmp*a[j])%mod;
			if (tmp==mod-1) tmp=-1;
			h=(233ll*h+tmp+3)%mod;
			h2=(233ll*h2+tmp+3)%mod2;
		}
		cc[i]=c[1];
		ll tmp=(cc[i]-2ll*cc[i-1]+2*mod)%mod;
		del[i]=tmp;
		if (vis.count(mp(h,h2))){
			if (!l) l=vis[mp(h,h2)]+1,r=i;
			break;
		}
		vis[mp(h,h2)]=i;
	}
	int A=1,B=0;
	For(i,l,r){
		A=2ll*A%mod;
		B=(2ll*B+del[i]+mod)%mod;
		tr[i]=mp(A,B);
	}
	base.a[0][0]=A,base.a[0][1]=0;
	base.a[1][0]=B,base.a[1][1]=1;
	ll S=0;
	For(i,1,q){
		ll k=rd(seed)%kmx;
		int t=0;
		if (k<=r) t=Ans[k];
		else {
			mat tmp=power(base,(k-r)/(r-l+1));
			mat f;
			f.a[0][0]=cc[r],f.a[0][1]=1;
			f=f*tmp;
			t=f.a[0][0];
			int tt=(k-r)%(r-l+1)+l-1;
			if (tt>=l) t=(1ll*tr[tt].fi*t+tr[tt].se)%mod;
			t=(1ll*t*all+ss[tt<l?r:tt])%mod;
		}
		t=1ll*t*power((mod+1)/2,k)%mod;
		S^=1ll*t*i;
	}
	printf("%lld\n",S);
}

int main(){
	freopen("noodle.in","r",stdin);
	freopen("noodle.out","w",stdout);
	id=read();
	int T=read();
	scanf("%llu",&seed);
	For(i,1,T){
		solve(i);
	}
}
