#include<map> #include<set> #include<list> #include<cmath> #include<ctime> #include<deque> #include<stack> #include<bitset> #include<cstdio> #include<vector> #include<cstdlib> #include<cstring> #include<iomanip> #include<numeric> #include<sstream> #include<utility> #include<iostream> #include<algorithm> #include<functional> using namespace std ; int main() { int Case , n , k ; int op1[ 10005 ] , op2[ 10005 ] ; cin >> Case ; while( Case-- ) { cin >> n >> k ; for( int i = 0 ; i < n ; ++i ) { scanf( "%d" , &op1[ i ] ) ; } //sort( op1 , op1 + n ) ; /* for( int i = 0 ; i < n ; ++i ) printf( "%d\n" , op1[ i ] ); do { for( int i = 0 ; i < n ; ++i ) printf( "%d" , op1[ i ] ); printf( "\n" ) ; }while( next_permutation( op1 , op1 + n ) );*/ while( k-- ) next_permutation( op1 , op1 + n ) ; for( int i = 0 ; i < n - 1 ; ++i ) printf( "%d " , op1[ i ] ); printf( "%d\n" , op1[ n - 1 ] ) ; } return 0; }