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

#define ll long long

int read() {
	int f = 1 , j = 0 ; char c = getchar() ;
	while ( c < '0' || c > '9' ) { if ( c == '-' ) { f = -1 ; } c = getchar() ; }
	while ( c >= '0' && c <= '9' ) { j = ( j << 1 ) + ( j << 3 ) + ( c ^ 48 ) ; c = getchar() ; }
	return f * j ;
}

void write( ll x ) {
	int l = 0 ; char c[200] ;
	if ( x < 0 ) { putchar('-') ; x = -x ; }
	do { c[++l] = x % 10 + 48 ; x /= 10 ; } while (x) ;
	do { putchar(c[l--]) ; } while (l) ;
	putchar('\n') ;
}

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

const int N = 2e6 + 10 ;
const int M = 2e6 ;
const int S = 2e3 + 10 ;
const int Mod = 998244353 ;

struct Node {
	int x , y ;
	int c[S][S] ;
} ;

struct node {
	int x , id ;
	bool operator < ( const node &y ) const {
		return x < y.x ;
	}
} b[N] ;

int n , p , q , cnt , mx , a[N] , d[N] ;
long long ans ;

int chk( Node x , int ret = 0 ) {
	for ( int i = 1 ; i <= x.x ; i ++ ) {
		for ( int j = 1 ; j <= x.y ; j ++ ) {
			if ( x.c[i][j] != 0 ) { ret ++ ; }
		}
	}
	return ret ;
}

int power( int x , int y , int res = 1 ) {
	for ( ; y ; y >>= 1 ) {
		if ( y & 1 ) { res = 1ll * res * x % Mod ; }
		x = 1ll * x * x % Mod ; 
	} return res ;
}

int add( int x , int y ) { return x + y >= Mod ? x + y - Mod : x + y ; }

Node calc( Node x , Node y ) {
	Node z ; z.x = y.x ; z.y = x.y ;
	/*
	cerr << x.x << " " << x.y << " " << y.x << " " << y.y << endl ;
	if ( x.x == x.y ) {
		for ( int i = 1 ; i <= x.x ; i ++ ) {
			for ( int j = 1 ; j <= x.y ; j ++ ) {
				cerr << x.c[i][j] << " " ;
			} cerr << endl ;
		}
	}
	*/
	for ( int i = 1 ; i <= z.x ; i ++ ) {
		for ( int j = 1 ; j <= z.y ; j ++ ) {
			z.c[i][j] = 0 ;
			for ( int k = 1 ; k <= x.x ; k ++ ) {
				z.c[i][j] = add( z.c[i][j] , 1ll * y.c[i][k] * x.c[k][j] % Mod ) ;
			}
		}
	}
	/*
	cerr << 1ll * 3 * power( 4 , Mod - 2 ) % Mod << "???" << endl ;
	if ( x.x == x.y ) {
		for ( int i = 1 ; i <= z.x ; i ++ ) {
			for ( int j = 1 ; j <= z.y ; j ++ ) {
				cerr << z.c[i][j] << " " ;
			} cerr << endl ;
		}
	}
	*/
	return z ;
}

Node Power( Node x , int y , Node res ) {
	for ( ; y ; y >>= 1 ) {
		if ( y & 1 ) { res = calc( res , x ) ; }
		x = calc( x , x ) ; //cerr << chk(x) << endl ;
	} return res ;
}

void solve() {
	cnt = 1 ;
	while ( cnt <= q && b[cnt].x == 0 ) { ans ^= ( 1ll * a[p] * b[cnt].id ) ; cnt ++ ; }
	if ( b[q].x <= 1000 ) {
		for ( int k = 1 ; k <= b[q].x ; k ++ ) {
			for ( int i = 1 ; i <= n / 2 ; i ++ ) { d[i] = a[i] + a[n - i + 1] ; }
			for ( int i = 1 ; i <= n ; i ++ ) { a[i] = 1ll * power( 2 , Mod - 2 ) * d[( i + 1 ) / 2] % Mod ; }
			while ( cnt <= q && b[cnt].x == k ) { ans ^= ( 1ll * a[p] * b[cnt].id ) ; cnt ++ ; }
		}
		return ;
	}
	for ( int k = 1 ; k <= 30 ; k ++ ) {
		for ( int i = 1 ; i <= n / 2 ; i ++ ) { d[i] = a[i] + a[n - i + 1] ; }
		for ( int i = 1 ; i <= n ; i ++ ) { a[i] = 1ll * power( 2 , Mod - 2 ) * d[( i + 1 ) / 2] % Mod ; }
		while ( cnt <= q && b[cnt].x == k ) { ans ^= ( 1ll * a[p] * b[cnt].id ) ; cnt ++ ; }
	}
//	for ( int i = 1 ; i <= n ; i ++ ) { cerr << a[i] << " " ; } cerr << endl ;
	if ( cnt > q ) { return ; }
	int x = n , cntx = 0 , cnty = 0 , mx = b[q].x ;
	while ( x % 2 == 0 ) { x /= 2 ; cnty ++ ; }
	cntx = x / 2 ;
	if ( cntx > 2000 ) { return ; }
//	cerr << n << " " << cntx << " " << cnty << endl ;
	Node A , B ;
	A.x = cntx + 1 ; A.y = 1 ; int y = power( 2 , cnty ) ;
	for ( int i = 1 ; i <= cntx ; i ++ ) {
		A.c[i][1] = a[i * y * 2] ;
	} A.c[cntx + 1][1] = a[n] ;
//	for ( int i = 1 ; i <= y ; i ++ ) cerr << A.c[i][1] << endl ;
//	cerr << A.c[1][1] << " " << A.c[2][1] << endl ;
	B.x = B.y = cntx + 1 ; int Q = power( 2 , Mod - 2 ) ;
	for ( int i = 1 ; i <= cntx + 1 ; i ++ ) {
		B.c[i][( i + y - 1 ) / y] = Q ;
	}
	B.c[cntx + 1][cntx / y + 1] = 1 ;
	for ( int i = 1 ; i <= y / 2 ; i ++ ) {
		B.c[i][cntx + 1] = Q ;
	}
	for ( int i = y / 2 + 1 ; i <= cntx + 1 ; i ++ ) {
		B.c[i][cnt - ( i - y / 2 - 1 ) / y] = Q ;
	}
//	cerr << p << " " << power( 2 , cnty ) * 2 << endl ;
	int k = ( p + y * 2 - 1 ) / ( y * 2 ) ;
//	cerr << n << " " << p << " " << cnty << " " << cntx << " " << k << " " << power( 2 , cnty ) * 2 << endl ;
	A = calc( A , Power( B , b[cnt].x - 31 , B ) ) ; //cerr << A.x << " " << A.y << " " << k << " " << cntx << endl ;
	ll w = 1ll * A.c[k][1] * b[cnt].id ;
	ans ^= w ; cnt ++ ;
	for ( ; cnt <= q ; cnt ++ ) {
		if ( b[cnt].x != b[cnt - 1].x ) { A = calc( A , Power( B , b[cnt].x - b[cnt - 1].x - 1 , B ) ) ; }
		w = 1ll * A.c[k][1] * b[cnt].id ; ans ^= w ;
	}
}

signed main() {
	freopen( "noodle.in" , "r" , stdin ) ; freopen( "noodle.out" , "w" , stdout ) ;
	int test = read() , T = read() ;
	unsigned long long seed ;
	scanf( "%llu" , &seed ) ;
	for( int Case = 1 ; Case <= T ; Case ++ ) {
		long long k_max ; n = read() ; q = read() ; p = read() ;
		scanf( "%lld", &k_max ) ;
		for( int i = 1 ; i <= n ; i ++ ) { a[i] = read() ; }
		for( int i = 1 ; i <= q ; i ++ ) {
			long long k = rd(seed) % k_max ;
			b[i].x = k ; b[i].id = i ;
		}
		sort( b + 1 , b + q + 1 ) ;
		ans = 0 ; solve() ; write(ans) ;
	}
}
