#include<bits/stdc++.h>
#define pb push_back
#define SZ(x) (int)((x).size())
template<typename _Tp>void read(_Tp &x){
	char ch=getchar();bool f=0;while(!isdigit(ch))f|=ch=='-',ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template<typename _Tp,typename ...Args>void read(_Tp &x,Args &...args){read(x),read(args...);}
const int N=200005,NC=(1<<19)+5;
int a[N],b[N],t[N];
std::vector<int> vec[N];
struct node{int sum,lsum,rsum,ans;}f[NC];int M;
inline node merge(const node &a,const node &b){return {a.sum+b.sum,std::max(a.lsum,a.sum+b.lsum),std::max(a.rsum+b.sum,b.rsum),std::max({a.ans,b.ans,a.rsum+b.lsum})};}
void build(int n){
	for(M=1;M<=n+2;M<<=1);
	std::fill(f,f+M*2+3,(node){0,0,0,0});
}
void upd(int x,int C){f[x+=M]={C,C,C,C};for(x>>=1;x;x>>=1)f[x]=merge(f[x<<1],f[x<<1|1]);}
void MAIN(){
	int n;read(n);
	for(int i=1;i<=n;++i)read(a[i]),t[i]=a[i];
	std::sort(t+1,t+n+1);int pos=std::unique(t+1,t+n+1)-t-1;
	for(int i=0;i<=pos;++i)vec[i].clear();
	for(int i=1;i<=n;++i)b[i]=std::lower_bound(t+1,t+pos+1,a[i])-t,vec[b[i]].pb(i);
	build(n);int ans=0;std::vector<int> res;
	for(int i=1;i<=pos;++i){
		int cur=SZ(vec[i]),mx=cur;
		for(auto it:vec[i])upd(it,-1);
		for(int j=1;j<=pos;++j)if(i!=j){
			for(auto it:vec[j])upd(it,1);
			mx=std::max(mx,cur+f[1].ans);
			for(auto it:vec[j])upd(it,0);
		}
		for(auto it:vec[i])upd(it,0);
		if(mx>ans)ans=mx,res={t[i]};else if(mx==ans)res.pb(t[i]);
	}
	printf("%d\n",ans);
	for(auto it:res)printf("%d\n",it);
}
int main(){
	int _;read(_);
	while(_--)MAIN();
	return 0;
}
