#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; ++ i)
#define per(i, a, n) for(int i = n; i >= a; -- i)
#define make_pair mkp
#define Max(a,b) (a)>(b)?(a):(b)
#define Min(a,b) (a)<(b)?(a):(b)
#define Swap(a,b) (a)^=(b)^=(a)^=(b)
typedef long long ll;
typedef pair<int ,int> pii;
const int N = 2e5+105;
const int mod = 998244353;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
ll qpow(ll a, ll b) { ll res = 1; while(b){ if(b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1;} return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
//
int T, n;
int a[N];
int sum[N][205];
vector<int>si[N];
int main()
{
scanf("%d",&T);
while(T --){
scanf("%d",&n);
for(int i = 1; i <= n; ++ i){
scanf("%d",&a[i]);
si[a[i]].push_back(i);
}
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= 200; ++ j)
sum[i][j] = sum[i - 1][j] + (a[i] == j);
int res = 0, val = 0;
for(int i = 1; i <= 200; ++ i){
res = max(res, sum[n][i]);
for(int j = 0; j < si[i].size() / 2; ++ j){
int t1 = si[i][j];
int t2 = si[i][(si[i].size() - j - 1)];
val = sum[t1][i] + sum[n][i] - sum[t2 - 1][i];
for(int k = 1; k <= 200; ++ k){
res = max(res,val + sum[t2 - 1][k] - sum[t1][k]);
}
}
si[i].clear();
}
printf("%d
",res);
}
return 0;
}