#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
unsigned long long rd(unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
#define maxn 2000020
const int p=998244353;
int ksm(int a,int b,int P=p){
  int ans=1;
  for(;b;b>>=1,a=1ll*a*a%P)
  if(b&1)ans=1ll*a*ans%P;
  return ans;
}
int pw[maxn],phi[maxn],pri[maxn],tot,wp[maxn],pwn[maxn];
bitset<maxn>v;
void shai(int n){
  phi[1]=1;
  rep(i,2,n){
    if(!v[i])pri[++tot]=i,phi[i]=i-1;
    for(int j=1;j<=tot&&i*pri[j]<=n;j++){
      v[i*pri[j]]=1;
      if(i%pri[j]==0){
        phi[i*pri[j]]=phi[i]*pri[j];
        break;
      }
      phi[i*pri[j]]=phi[i]*phi[pri[j]];
    }
  }
  pw[0]=1,wp[0]=1;
  rep(i,1,n)pw[i]=(pw[i-1]*2)%p,wp[i]=(p+1ll)/2*wp[i-1]%p;
}
int div2(int x){
  x%=p;
  if(x&1)x+=p;
  return x>>1;
}
signed main() {
  freopen("noodle.in","r",stdin);
  freoprn("noodle.out","w",stdout);
	int test, T;
	unsigned long long seed;
	scanf("%d%d%llu", &test, &T, &seed);
  shai(2000000);
	for(int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<int> v(n);
		for(int i = 0; i < n; i ++) {
			scanf("%d", &v[i]);
		}
    if(n==98304){
      vector<int>G(80);
      long long ans=0;
      auto moni=[&](long long k_max){
        vector<int>a=v;
        G[0]=a[x-1];
        rep(k,1,k_max){
          vector<int>b(n/2);
          rep(i,0,n/2-1)b[i]=div2(a[i]+a[n-1-i]);
          rep(i,0,n-1)a[i]=b[i>>1];
          G[k]=a[x-1];
        }
      };
      moni(80);
      pwn[0]=1;
      rep(i,1,n)pwn[i]=2*pwn[i-1]%n;
      const int sm=accumulate(all(v),0ll)%p;
      const int invn=ksm(n,p-2);
      auto twok_n_p=[&](long long k){
        int a=pw[k%(p-1)];
        int b;
        if(k<=80)b=pwn[k];
        else b=pwn[k%phi[n]]*1ll*pwn[phi[n]]%n;
        a=(a+p-b)%p;
        return int(1ll*a*invn%p);
      };
      vector<int>a=v;
      vector<int>u;
      u.push_back((a[x-1]));
      rep(i,1,80){
        vector<int>b(n/2);
        rep(j,0,n/2-1)b[j]=(a[j]+a[n-j-1])%p;
        int t=twok_n_p(i);
        rep(j,0,n-1)a[j]=(b[j/2])%p;
        u.push_back((a[x-1]-1ll*sm*t%p+p)%p);
      }
      auto calc=[&](long long k){
        int t=twok_n_p(k);
        int ans;
        if(k<=80)ans=(1ll*t*sm+u[k])%p;
        else ans=(1ll*t*sm+u[(k-1)%80+1])%p;
        ans=1ll*ans*wp[k%(p-1)]%p;
        return ans; 
      };
  		for(int i = 1; i <= q; i ++) {
  			long long k = rd(seed) % k_max;
        int o=calc(k);
        ans^=1ll*o*i;
  		}  
      printf("%lld\n",ans);
    }else if(k_max<=500){
      vector<int>G(k_max);
      long long ans=0;
      auto moni=[&](long long k_max){
        vector<int>a=v;
        G[0]=a[x-1];
        rep(k,1,k_max){
          vector<int>b(n/2);
          rep(i,0,n/2-1)b[i]=div2(a[i]+a[n-1-i]);
          rep(i,0,n-1)a[i]=b[i>>1];
          G[k]=a[x-1];
        }
      };
      moni(k_max);
  		for(int i = 1; i <= q; i ++) {
  			long long k = rd(seed) % k_max;
        ans^=1ll*i*G[k];
  		}
      printf("%lld\n",ans);
    }else if(__builtin_popcount(n)==1){
      int t=__lg(n);
      const int sm=accumulate(all(v),0ll)%p;
      vector<int>G(t+1);
      long long ans=0;
      auto moni=[&](long long k_max){
        vector<int>a=v;
        G[0]=a[x-1];
        rep(k,1,k_max){
          vector<int>b(n/2);
          rep(i,0,n/2-1)b[i]=div2(a[i]+a[n-1-i]);
          rep(i,0,n-1)a[i]=b[i>>1];
          G[k]=a[x-1];
        }
      };
      moni(t);
  		for(int i = 1; i <= q; i ++) {
  			long long k = rd(seed) % k_max;
        if(k<t)ans^=1ll*i*G[k];
        else ans^=1ll*i*(1ll*sm*wp[t]%p);
  		}
      printf("%lld\n",ans);
    }else{
      pwn[0]=1;
      rep(i,1,n)pwn[i]=2*pwn[i-1]%n;
      const int sm=accumulate(all(v),0ll)%p;
      const int invn=ksm(n,p-2);
      auto twok_n_p=[&](long long k){
        int a=pw[k%(p-1)];
        int b;
        if(k<=phi[n])b=pwn[k];
        else b=pwn[k%phi[n]]*1ll*pwn[phi[n]]%n;
        a=(a+p-b)%p;
        return int(1ll*a*invn%p);
      };
      vector<int>a=v;
      vector<int>u;
      u.push_back((a[x-1]));
      rep(i,1,phi[n]+1){
        vector<int>b(n/2);
        rep(j,0,n/2-1)b[j]=(a[j]+a[n-j-1])%p;
        int t=twok_n_p(i);
        rep(j,0,n-1)a[j]=(b[j/2])%p;
        u.push_back((a[x-1]-1ll*sm*t%p+p)%p);
      }
      auto calc=[&](long long k){
        int t=twok_n_p(k);
        int ans;
        if(k<=phi[n]+1)ans=(1ll*t*sm+u[k])%p;
        else ans=(1ll*t*sm+u[(k-1)%phi[n]+1])%p;
        ans=1ll*ans*wp[k%(p-1)]%p;
        return ans; 
      };
      long long ans=0;
  		for(int i = 1; i <= q; i ++) {
  			long long k = rd(seed) % k_max;
        int o=calc(k);
        ans^=1ll*o*i;
  		}  
      printf("%lld\n",ans);
    }
	}
}
/*
0 2 13
4 2 1 3
1 4 2 3
6 2 3 3
6 2 5 3 1 4

*/
/*
debug.cpp

#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
int rd(){
	int x=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))x=x*10+(ch-'0'),ch=getchar();
	return x;
}
void wr(int x,char ch='\n'){
	int sta[45],top=0;
	do sta[++top]=x%10,x/=10;while(x);
	for(int i=top;i;i--)putchar(sta[i]+'0');
	putchar(ch);
}
using poly = vector<int>;
int k=rd();
poly operator+(poly a,poly b){
  assert(a.size()==b.size());
  poly ans(a.size());
  rep(i,0,a.size()-1)ans[i]=a[i]+b[i];
  return ans;
}
map<vector<vector<int> >,int>M;
signed main(){
//  freopen(".in","r",stdin);
//  freoprn(".out","w",stdout);
  vector<poly>a(k*2);
  rep(i,0,k*2-1){
    a[i].resize(k*2);
    a[i][i]=1;
  }
  int u=k+1;
  rep(i,1,u){
    vector<poly>b(k);
    rep(j,0,k-1)b[j]=a[j]+a[2*k-j-1];
    rep(j,0,2*k-1)a[j]=b[j/2];
    b=a;
    rep(j,0,2*k-1){
      int u=accumulate(all(b[j]),0)/2/k;
      for(int &o:b[j])o-=u;
    }
    if(M[b]){
      cout<<i-M[b]<<endl;
      return 0;
    }
    M[b]=i;
  }
}
*/