#include <bits/stdc++.h> 
using namespace std ; 
namespace hater_space { 

#define fp( i , x , y ) for( int i=(x); i<=(y); ++i ) 
#define fq( i , x , y ) for( int i=(y); i>=(x); --i ) 
#define i60 long long 
#define dou double 
#define u60 unsigned long long 
#define IL inline 
const int mod = 998244353 , N = 505 ;  
IL int R( int x ) { return x >= mod ? x-mod : x ; } 
u60 rd(u60 &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}
int ta[N] , a[N] , b[N] ; 
int main( ) { 
  freopen( "noodle.in" , "r" , stdin ) ; 
  freopen( "noodle.out" , "w" , stdout ) ; 
  int test , T ; u60 seed ; i60 Ans = 0 ; 
  ios::sync_with_stdio(false) ; 
  cin.tie(0) ; 
  cin >> test >> T >> seed ; 
  int iv2 = (mod+1)/2 , nw , n , q , x , km ; 
  assert( 2ll * iv2 % mod == 1 ) ; 
  while( T -- ) { 
    cin >> n >> q >> x >> km ; Ans = 0 ; 
    fp( i , 1 , n ) cin >> a[i] , ta[i] = a[i] ;  
    nw = 1 ; 
    while( q -- ) { 
      memcpy( a , ta , sizeof(a) ) ; 
      i60 k = rd(seed) % km ;  
      while( k -- ) { 
        fp( i , 1 , n/2 ) b[i] = R( a[i] + a[n-i+1] ) ; 
        fp( i , 1 , n ) a[i] = 1ll * iv2 * b[(i-1)/2+1] % mod ; 
	  } 
      Ans ^= 1ll * a[x] * nw ; 
	  nw ++ ; 
	} 
	cout << Ans << '\n' ; 
  }  
  return 0 ; 
} 

} 
int main( ) { 
  hater_space::main() ; 
  return 0 ; 
} 
