#include <bits/stdc++.h>

#define see(x) std::cout << #x << " = " << x << std::endl
template <class T, typename = typename T::iterator>
std::ostream &operator<< (std::ostream &out, const T &v)
{
	out << "{";
	for (const auto &x : v) out << x << ", ";
	out << "}";
	return out;
}

int init_io = []{
#ifndef CM_DEBUG
	freopen("mode.in", "r", stdin);
	freopen("mode.out", "w", stdout);
#endif
	return 0;
}();

const int N = 200005;
int a[N], n;
std::vector<int> vals;
std::vector<int> b[N * 2];

int mss(const std::vector<int> &a)
{
	int min_pre = 0, cur = 0, ans = 0;
	for (int v : a)
	{
		cur += v;
		min_pre = std::min(min_pre, cur);
		ans = std::max(ans, cur - min_pre);
	}
	return ans;
}

void rmain()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	vals.clear();
	for (int i = 0; i < n; i++)
		vals.push_back(a[i]);
	std::sort(vals.begin(), vals.end());
	vals.erase(std::unique(vals.begin(), vals.end()), vals.end());

	for (size_t i = 0; i < vals.size(); i++)
		b[i].clear();
	for (int i = 0; i < n; i++)
	{
		a[i] = static_cast<int>(std::lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin());
		b[a[i]].push_back(i);
	}

	int ans_v = 0;
	std::vector<int> ans_s;

	std::vector<int> ord;
	for (int i = 0; i < (int)vals.size(); i++)
		ord.push_back(i);
	std::sort(ord.begin(), ord.end(), [](int x, int y) { return b[x].size() > b[y].size(); });

	for (int x: ord) for (int y: ord) if (x != y)
	{
		if ((int)(b[x].size() + b[y].size()) < ans_v) break;

		std::vector<int> v;

		auto itx = b[x].begin();
		auto ity = b[y].begin();
		while (itx != b[x].end() || ity != b[y].end())
		{
			if (itx != b[x].end() && (ity == b[y].end() || *itx < *ity))
			{
				v.push_back(-1);
				itx++;
			}
			else
			{
				v.push_back(1);
				ity++;
			}
		}

		int cur_ans = (int)b[x].size() + mss(v);
		if (cur_ans > ans_v)
		{
			ans_v = cur_ans;
			ans_s = {vals[x]};
		}
		else if (cur_ans == ans_v)
		{
			ans_s.push_back(vals[x]);
		}
	}

	std::sort(ans_s.begin(), ans_s.end());
	ans_s.erase(std::unique(ans_s.begin(), ans_s.end()), ans_s.end());
	printf("%d\n", ans_v);
	for (int x : ans_s)
		printf("%d\n", x);
}

int main()
{
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
		rmain();
	return 0;
}
