1 #include<cstdio>
2 #include<algorithm>
3 #include<string.h>
4 using namespace std;
5 #define MAXN 2050
6 int str[MAXN];
7 int main()
8 {
9 int m,n,k,i;
10 scanf("%d",&m);
11 while(m--)
12 {
13 memset(str,0,sizeof(str));
14 scanf("%d%d",&n,&k);
15 for(i=0;i<n;i++)
16 scanf("%d",&str[i]);
17 for(i=1;i<=k;i++)
18 {
19 next_permutation(str,str+n);
20 }
21 for(i=0;i<n-1;i++)
22 printf("%d ",str[i]);
23 printf("%d\n",str[i]);
24 }
25 return 0;
26 }