#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
k=k%n;
int s;
s=n-k;
vector<int>v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
reverse(v.begin(),v.begin()+s);
reverse(v.begin()+s,v.end());
reverse(v.begin(),v.end());
for(int i=0;i<n;i++){
cout<<v[i]<<" ";
}
cout<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgdDsKCWNpbj4+dDsKCXdoaWxlKHQtLSl7CgkJaW50IG4sazsKCQljaW4+Pm4+Pms7CgkJaz1rJW47CgkJaW50IHM7CgkJcz1uLWs7CgkJdmVjdG9yPGludD52KG4pOwoJCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCQljaW4+PnZbaV07CgkgIH0KCXJldmVyc2Uodi5iZWdpbigpLHYuYmVnaW4oKStzKTsKCXJldmVyc2Uodi5iZWdpbigpK3Msdi5lbmQoKSk7CglyZXZlcnNlKHYuYmVnaW4oKSx2LmVuZCgpKTsKCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCWNvdXQ8PHZbaV08PCIgIjsKCX0KCWNvdXQ8PCJcbiI7Cgl9CglyZXR1cm4gMDsKfQ==