#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<vector<int>>;
using ll = long long;
using uii = unordered_map<int, int>;
using ui = unordered_set<int>;


#define MOD 1000000007
#define INF 1e9
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#define FORF(a, b, c) for (int a = b; a <= c; ++a)
#define FORB(a, b, c) for (int a = b; a >= c; --a)
#define sc second
#define fr first




void solve() {
    int n, m;
    cin >> n >> m;
    unordered_map<int, int> e;
    FOR(i,0,m){
        int x;
        cin >> x;
        e[x]++;
        
    }
    vi answer;
    for (auto i: e){
        if (i.second >= n) answer.push_back(i.first);
    }
    cout << answer.size() << "\n";
    for (int i: answer) cout << i << " ";
    cout << "\n";
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
