#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define each(x,v) for(auto&x:v)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
using namespace std;
template<class T>void rd(T&x){
	int f=0,c;
	while(c=getchar(),!isdigit(c))f^=!(c^45);
	x=c&15;
	while(c=getchar(),isdigit(c))x=x*10+(c&15);
	if(f)x=-x;
}
const int N=200005;
int T,n,m,a[N],b[N],sum[N];
int calc(int x,int y){ // change x to y
	int now=0,mn=0,ret=0,tt=0;
	rep(i,1,n){
		tt+=a[i]==y;
		now+=a[i]==y?-1:a[i]==x?1:0;
		ret=max(ret,now-mn);
		mn=min(mn,now);
	}
	return ret+tt;
}
int main(){
	freopen("mode.in","r",stdin);
	freopen("mode.out","w",stdout);
	rd(T);
	while(T--){
		rd(n);
		rep(i,1,n)rd(a[i]),b[i]=a[i];
		sort(b+1,b+n+1);
		int m=unique(b+1,b+n+1)-b-1;
		rep(i,1,n)a[i]=lower_bound(b+1,b+m+1,a[i])-b;
		int mx=0;
		vector<int>v;
		rep(i,1,m)rep(j,1,m)if(i!=j){
			int cur=calc(j,i);
			if(cur>mx){
				mx=cur;
				v.clear();
			}
			if(cur==mx&&(v.empty()||v.back()!=i))v.pb(i);
		}
		printf("%d\n",mx);
		each(x,v)printf("%d\n",b[x]);
	}
	return 0;
}
