#include <bits/stdc++.h>
using namespace std;
#define R(i, a, b) for (int i = (a); i < (b); ++i)
#define L(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using i64 = long long;
constexpr int xn = 200007;
int n, A[xn], nA, wA[xn], cnt[xn];
vector<int> setA[xn];
void solveT() {
  cin >> n; nA = 0;
  R(i, 0, n) {
    cin >> A[i]; wA[nA++] = A[i];
  }
  sort(wA, wA + nA); nA = unique(wA, wA + nA) - wA;
  R(i, 0, n) {
    A[i] = lower_bound(wA, wA + nA, A[i]) - wA;
    setA[A[i]].push_back(i); cnt[A[i]] += 1;
  }
  int res = 0;
  vector<int> rm;
  R(x, 0, nA) R(y, x + 1, nA) {
    vector<int> C;
    auto i = setA[x].begin(), j = setA[y].begin();
    for (; i != setA[x].end() and j != setA[y].end(); ) {
      if (*i < *j) {
        C.push_back(1); ++i;
      } else {
        C.push_back(-1); ++j;
      }
    }
    for (; i != setA[x].end(); ++i) C.push_back(1);
    for (; j != setA[y].end(); ++j) C.push_back(-1);
    int rx = 0, mx = 0, ry = 0, my = 0;
    for (const int &w : C) {
      mx -= w; if (mx < 0) mx = 0; rx = max(rx, mx);
      my += w; if (my < 0) my = 0; ry = max(ry, my);
    }
    rx += cnt[x]; ry += cnt[y];
    if (rx > res) {
      res = rx; rm = {wA[x]};
    } else if (rx == res) rm.push_back(wA[x]);
    if (ry > res) {
      res = ry; rm = {wA[y]};
    } else if (ry == res) rm.push_back(wA[y]); 
  } 
  sort(rm.begin(), rm.end());
  rm.resize(unique(rm.begin(), rm.end()) - rm.begin());
  cout << res << '\n';
  for (const int &x : rm) cout << x << '\n';
  fill(cnt, cnt + nA, 0);
  R(i, 0, nA) setA[i].clear();
}
int main() {
  freopen("mode.in", "r", stdin); freopen("mode.out", "w", stdout);
  ios::sync_with_stdio(false); cin.tie(0);
  int nT; cin >> nT; R(T, 0, nT) solveT();
  return 0;
}