#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define vt vector
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define ent "\n"
#define sp ' '

using ll  = long long;
using db  = double;
using ldb = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

const ll  INF = 8e18;
const ll  inf = 1e9 + 7;
const int MOD = 998244353;
const int bln = 200;
const int M   = 1e2 + 7;
const int N   = 1e6 + 7;

/*-------------------------main-------------------------*/

int a[N];
void solve() {
    #define test
    int m, n; cin >> m >> n;
    map<int, int> cnt;
    for(int i = 1; i <= n; ++i) cin >> a[i], cnt[a[i]]++;
    vector<int> ans;
    for(auto cur : cnt) {
       // cout << cur.first << " " << cur.second << "\n";
        if(cur.second >= m) ans.pb(cur.first);
    }
    cout << ans.size() << "\n";
    for(auto cur : ans) cout << cur << " ";
}

void precalc() {
}

signed main() {
//  freopen("guard.in", "r", stdin);
//  freopen("guard.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    precalc();
    int testcases;
    #ifdef tests
        cin >> testcases;
    #endif
    #ifdef test
        testcases = 1;
    #endif
    while (testcases--) {
        solve();
    }
    return 0;
}
