#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
void Ktop(int *arr, int n, int k) {
vector<int> top(k+1);
unordered_map<int, int> freq;
for(int m=0;m<n;m++) {
freq[arr[m]]++;
top[k] = arr[m];
auto it = find(top.begin(), top.end()-1, arr[m]);
for(int i=distance(top.begin(), it)-1;i>=0;i--) {
if(freq[top[i]]<freq[top[i+1]]) {
swap(top[i], top[i+1]);
} else if(freq[top[i]]==freq[top[i+1]] and top[i]>top[i+1]) {
swap(top[i], top[i+1]);
} else {
break;
}
}
for (int i = 0; i < k && top[i] != 0; ++i)
cout << top[i] << ' ';
}
cout<<endl;
}
int main(int argc, char const *argv[])
{
/* code */
int t;
cin>>t;
while(t--) {
int n, k;
cin>>n>>k;
int *arr = new int[n];
for(int i=0;i<n;i++) {
cin>>arr[i];
}
Ktop(arr, n, k);
delete [] arr;
}
return 0;
}
CgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDx1bm9yZGVyZWRfbWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBLdG9wKGludCAqYXJyLCBpbnQgbiwgaW50IGspIHsKICAgIHZlY3RvcjxpbnQ+IHRvcChrKzEpOwogICAgdW5vcmRlcmVkX21hcDxpbnQsIGludD4gZnJlcTsKICAgIGZvcihpbnQgbT0wO208bjttKyspIHsKICAgICAgICBmcmVxW2FyclttXV0rKzsKICAgICAgICB0b3Bba10gPSBhcnJbbV07CiAgICAgICAgYXV0byBpdCA9IGZpbmQodG9wLmJlZ2luKCksIHRvcC5lbmQoKS0xLCBhcnJbbV0pOwogICAgICAgIGZvcihpbnQgaT1kaXN0YW5jZSh0b3AuYmVnaW4oKSwgaXQpLTE7aT49MDtpLS0pIHsKICAgICAgICAgICAgaWYoZnJlcVt0b3BbaV1dPGZyZXFbdG9wW2krMV1dKSB7CiAgICAgICAgICAgICAgICBzd2FwKHRvcFtpXSwgdG9wW2krMV0pOwogICAgICAgICAgICB9IGVsc2UgaWYoZnJlcVt0b3BbaV1dPT1mcmVxW3RvcFtpKzFdXSBhbmQgdG9wW2ldPnRvcFtpKzFdKSB7CiAgICAgICAgICAgICAgICBzd2FwKHRvcFtpXSwgdG9wW2krMV0pOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBrICYmIHRvcFtpXSAhPSAwOyArK2kpIAogICAgICAgICAgICBjb3V0IDw8IHRvcFtpXSA8PCAnICc7IAogICAgfQoKICAgIGNvdXQ8PGVuZGw7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyIGNvbnN0ICphcmd2W10pCnsKICAgIC8qIGNvZGUgKi8KICAgIGludCB0OwogICAgY2luPj50OwogICAgd2hpbGUodC0tKSB7CiAgICAgIGludCBuLCBrOwogICAgICBjaW4+Pm4+Pms7CiAgICAgIGludCAqYXJyID0gbmV3IGludFtuXTsKICAgICAgZm9yKGludCBpPTA7aTxuO2krKykgewogICAgICAgIGNpbj4+YXJyW2ldOwogICAgICB9CiAgICAgIEt0b3AoYXJyLCBuLCBrKTsKICAgICAgZGVsZXRlIFtdIGFycjsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==