#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0,f=0;
	for(;!isdigit(c);c=getchar())if(c=='-')f=1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint&operator =(int o){return x=o,*this;}
	modint&operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint&operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint&operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint&operator ^=(int b){
		modint c=1,a=*this;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint&operator /=(modint o){return (*this)*=(o^=(mod-2));}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	modint operator -(){return x?mod-x:0;}
};

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 200005
#define inf 0x3f3f3f3f

int n,a[maxn],m,res[maxn];
map<int,int>mp; int tov[maxn];
vi p[maxn];

inline int ID(int x){
	if(!mp.count(x))mp[x]=++m,tov[m]=x;
	return mp[x];
}

int solve(int u,int v)
{
	int pu=0,pv=0,now=0,mx=0;
	while(pu<p[u].size()||pv<p[v].size()){
		if(pv>=p[v].size()||(pu<p[u].size()&&p[u][pu]<p[v][pv]))
			--now,++pu;
		else ++now,++pv;
		if(now<0)now=0;
		mx=max(mx,now);
	}
	return p[u].size()+mx;
}

void work()
{
	n=read(),m=0,mp.clear();
	For(i,1,n)a[i]=read(),a[i]=ID(a[i]);
	For(i,1,n)p[a[i]].pb(i);
//	For(i,1,m)cout<<p[i].size()<<' ';puts("");
	For(i,1,m)
		For(j,1,m){
			if(i!=j){
				int tmp=solve(i,j);
		//		cout<<tmp<<' ';
				res[i]=max(res[i],tmp);
			}
		//	else cout<<"0 "; if(j==m)puts("");
		}
			
	int mx=0;
	For(i,1,m) mx=max(mx,res[i]);
	vi out;
	For(i,1,m) if(res[i]==mx) out.pb(tov[i]);
	printf("%d\n",mx);
	sort(out.begin(),out.end());
	for(auto x:out)printf("%d\n",x);
	For(i,1,m)p[i].clear(),res[i]=0;
}

signed main()
{
	freopen("mode.in","r",stdin);
	freopen("mode.out","w",stdout);
	int T=read();
	while(T--)work();
	return 0;
}
