#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Rg register
#define RI Rg int
#define Cn const
#define CI Cn int&
#define I inline
#define W while
#define N 200000
using namespace std;
namespace FastIO
{
	#define FS 100000
	#define tc() (FA==FB&&(FB=(FA=FI)+fread(FI,1,FS,stdin),FA==FB)?EOF:*FA++)
	#define pc(c) (FC==FE&&(clear(),0),*FC++=c)
	int OT;char oc,FI[FS],FO[FS],OS[30],*FA=FI,*FB=FI,*FC=FO,*FE=FO+FS;
	I void clear() {fwrite(FO,1,FC-FO,stdout),FC=FO;}
	Tp I void read(Ty& x) {x=0;W(!isdigit(oc=tc()));W(x=(x<<3)+(x<<1)+(oc&15),isdigit(oc=tc()));}
	Tp I void writeln(Ty x) {W(OS[++OT]=x%10+48,x/=10);W(OT) pc(OS[OT--]);pc('\n');}
}using namespace FastIO;
int n,a[N+5],s[N+5],c[N+5],w[N+5],dc,dv[N+5];vector<int> g[N+5];vector<int>::iterator it;
I int Calc(CI i,RI bg)
{
	RI j,u=g[i].size(),v=0,t=0;for(j=1;j<=dc;++j) w[j]=0;
	for(j=bg;j;--j) a[j]==i&&--u,v=max(v,++w[a[j]]),t=max(t,u+v);return t;
}
int f[N+5][3];I void SS()
{
	RI i,x,y,res,ans=0,ct=0;for(x=1;x<=dc;++x)
	{
		for(res=0,y=1;y<=dc;++y) if(x^y)
		{
			for(i=1;i<=n;++i) f[i][0]=f[i-1][0]+(a[i]==x),f[i][1]=max(f[i-1][0],f[i-1][1])+(a[i]==y),f[i][2]=max(f[i-1][1],f[i-1][2])+(a[i]==x);
			res=max(res,max(f[n][1],f[n][2]));
		}
		if(res>ans) ans=res,s[ct=1]=dv[x];else if(res==ans) s[++ct]=dv[x];
	}
	for(writeln(ans),i=1;i<=ct;++i) writeln(s[i]);
//	for(cerr<<ans<<endl,i=1;i<=ct;++i) cerr<<s[i]<<" ";cerr<<endl;
}
int main()
{
	freopen("mode.in","r",stdin),freopen("mode.out","w",stdout);
	RI Tt,i,j,res,ans,ct;read(Tt);W(Tt--)
	{
		for(read(n),i=1;i<=n;++i) read(a[i]),dv[i]=a[i];
		for(sort(dv+1,dv+n+1),dc=unique(dv+1,dv+n+1)-dv-1,i=1;i<=dc;++i) g[i].clear();
		#define GV(x) (lower_bound(dv+1,dv+dc+1,x)-dv)
		for(i=1;i<=n;++i) a[i]=GV(a[i]),g[a[i]].push_back(i);
		if(dc<=50) {SS();continue;}
		for(ans=ct=0,i=1;i<=dc;++i)
		{
			for(res=0,it=g[i].begin();it!=g[i].end();++it) res=max(res,Calc(i,*it-1));res=max(res,Calc(i,n));
			if(res>ans) ans=res,s[ct=1]=dv[i];else if(res==ans) s[++ct]=dv[i];
		}
		for(writeln(ans),i=1;i<=ct;++i) writeln(s[i]);
//		for(cerr<<ans<<endl,i=1;i<=ct;++i) cerr<<s[i]<<" ";cerr<<endl;
	}return clear(),0;
}