include<bits/stdc++.h>
define int long long
define F first
define S second
using namespace std;
int mod= 1e9+7;
int powerMod(int a, int b){ if(b==0){ return 1; } if(a%2==0){ return powerMod((a*a)%mod, b/2); } --b; return ( a * powerMod((a*a)%mod, b/2) )%mod ; }
int gcd(int a, int b){ return __gcd(a,b); }
int32_t main(){
int T=1;
cin>>T;
while(T--){
int n;
cin>>n;
int a[n];
vector<int>v[205];
int f[n][205];
//memset(f,0,sizeof(f));
for(int i=0;i<n;i++){
for(int j=0;j<=200;j++){
f[i][j]=0;
}
}
vector<int>mp(n,0);
for(int i=0;i<n;i++){
cin>>a[i];
v[a[i]].push_back(i);
if(i>0){
for(int j=1;j<=200;j++){
f[i][j]=f[i-1][j];
}
}
f[i][a[i]]++;
mp[i]=f[i][a[i]];
}
int ans=1;
for(int i=0;i<n;i++){
int cnt= mp[i], sz=v[a[i]].size();
if(cnt*2 > sz){
continue;
}
int x=v[a[i]][cnt-1];
int y=v[a[i]][sz-cnt];
int mx=0;
for(int j=1;j<=200;j++){
if(j==a[i]){
mx=max(mx,f[y][j]-f[x][j]-1);
}
else
mx=max(mx,f[y][j]-f[x][j]);
}
ans=max(ans,mx+cnt*2);
}
cout<<ans<<'\n';
}
return 0;
}