#include <bits/stdc++.h>

using namespace std;

pair<int, int> raw_a[200001];
int T, n, a[200001], mp[200001];

// INPUT

namespace sub1 {

int b[301][301], cnt[301][301][301], ans, ind, res[301];

void main() {
	memset(b, 0, sizeof(b));
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= n; ++i)
		for (int j = i; j <= n; ++j)
			for (int k = 1; k <= n; ++k)
				b[i][j] = max(b[i][j],
						cnt[i][j][k] = cnt[i][j - 1][k] + (a[j] == k));
	
	ans = ind = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= n; ++k) {
				int tmp = cnt[1][n][k] - cnt[i][j][k] + b[i][j];
				if (tmp > ans) {
					ans = tmp;
					res[ind = 1] = k;
				} else if (tmp == ans) res[++ind] = k;
			}
	printf("%d\n", ans);
	sort(res + 1, res + ind + 1);
	ind = unique(res + 1, res + ind + 1) - (res + 1);
	for (int i = 1; i <= ind; ++i) printf("%d\n", mp[res[i]]);
}

}

// 20 PTS

namespace sub2 {

int ans, ind, res[6];

void main() {
	ans = ind = 0;
	for (int b = 1; b <= 5; ++b) {
		int sum = 0, cur = 0;
		for (int i = 1; i <= n; ++i) sum += a[i] == b;
		for (int c = 1; c <= 5; ++c)
			for (int i = 1, minn = 0, cnt = 0; i <= n; ++i) {
				cnt += (a[i] == c) - (a[i] == b);
				minn = min(minn, cnt);
				cur = max(cur, sum + cnt - minn);
			}
		if (cur > ans) {
			ans = cur;
			res[ind = 1] = b;
		} else if (cur == ans) res[++ind] = b;
	}
	printf("%d\n", ans);
	for (int i = 1; i <= ind; ++i) printf("%d\n", mp[res[i]]);
}

}

// 40 PTS

int main() {
	freopen("mode.in", "r", stdin);
	freopen("mode.out", "w", stdout);
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &raw_a[i].first);
			raw_a[i].second = i;
		}
		sort(raw_a + 1, raw_a + n + 1);
		for (int i = 1, cnt = 0; i <= n; ++i) {
			if (raw_a[i].first > raw_a[i - 1].first)
				mp[++cnt] = raw_a[i].first;
			a[raw_a[i].second] = cnt;
		}
		if (n <= 300) sub1::main(); else sub2::main();
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
