#include<bits/stdc++.h>
#include<ctime>
///#include<fstream>
///#include<windows.h>
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long int
#define pb push_back
#define pf push_front
#define en cout<<endl;
#define yes cout<<"YES\n";
#define no  cout<<"NO\n";
#define no1 {cout<<-1<<'\n'; r0}
#define no0 {cout<<0<<'\n'; r0}
#define yes_r { cout<<"YES\n"; return ; }
#define no_r { cout<<"NO\n"; return ; }
#define r0 return ;
#define fr first
#define sc second
#define srt(name) sort(name.begin(), name.end());
#define rev(name) reverse(name.begin(), name.end());
#define TT { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; int tt; cin>>tt; while (tt--) not_main(); }
#define TT1 { not_main(); }
#define TTi { while(1) not_main(); }
#define IMP { cout<<"Impossible\n"; r0 }
#define PII pair<int, int>

const int INF=1e9+1;
const int mod=1e9+7;
const int N=1e5+1;

string all = "abcdefghijklmnopqrstuvwxyz";
string Call= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string Vow = "aeiou";
void not_main()
{
    int n, m;
    cin>>n>>m;
    int v[m];
    map<int, int> mp;
    set<int> st;

    for (int i=0; i<m; i++) {
        cin>>v[i];
        mp[v[i]]++;
    }

    for (int i=0; i<m; i++){
        if (mp[v[i]]>=n) st.insert(v[i]);
    }
    cout<<st.size()<<'\n';
    for (auto i:st)
    cout<<i<<' ';
}
int main()
{
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    TT1
}
