// title:Top K Frequent Elements
#include<bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
if(a.second!=b.second)
return a.second>b.second;
else
return a.first<b.first;
}
int main(){
// write your code here
int tq;
cin>>tq;
while(tq--)
{
int n,k;
cin>>n>>k;
map<int,int>mp;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
mp[a]++;
}
vector<pair<int,int>>p;
for(auto i:mp)
{
p.push_back(i);
}
sort(p.begin(),p.end(),cmp);
for(int i=0;i<n;i++)
{
if(i+1<=k)
{
cout<<p[i].first<<" ";
}
}
cout<<"\n";
}
return 0;
}
Ly8gdGl0bGU6VG9wIEsgRnJlcXVlbnQgRWxlbWVudHMKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKYm9vbCBjbXAocGFpcjxpbnQsaW50PiZhLHBhaXI8aW50LGludD4mYikKewogICAgaWYoYS5zZWNvbmQhPWIuc2Vjb25kKQogICAgICAgIHJldHVybiBhLnNlY29uZD5iLnNlY29uZDsKICAgIGVsc2UKICAgICAgICByZXR1cm4gYS5maXJzdDxiLmZpcnN0Owp9CmludCBtYWluKCl7CiAgIC8vIHdyaXRlIHlvdXIgY29kZSBoZXJlCiAgIGludCB0cTsKICAgY2luPj50cTsKICAgd2hpbGUodHEtLSkKICAgewogICAgICAgaW50IG4sazsKICAgICAgIGNpbj4+bj4+azsKICAgICAgIG1hcDxpbnQsaW50Pm1wOwogICAgICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgIHsKICAgICAgICAgICBpbnQgYTsKICAgICAgICAgICBjaW4+PmE7CiAgICAgICAgICAgbXBbYV0rKzsKICAgICAgIH0KICAgICAgIHZlY3RvcjxwYWlyPGludCxpbnQ+PnA7CiAgICAgICBmb3IoYXV0byBpOm1wKQogICAgICAgewogICAgICAgICAgIHAucHVzaF9iYWNrKGkpOwogICAgICAgfQogICAgICAgc29ydChwLmJlZ2luKCkscC5lbmQoKSxjbXApOwogICAgICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgIHsKICAgICAgICAgICBpZihpKzE8PWspCiAgICAgICAgICAgewogICAgICAgICAgICAgICBjb3V0PDxwW2ldLmZpcnN0PDwiICI7CiAgICAgICAgICAgfQogICAgICAgfQogICAgICAgY291dDw8IlxuIjsKICAgfQogICAgcmV0dXJuIDA7Cn0=