#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){

    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 200100;
int a[N];

const int MAXN = 400100;
ll tree[4*MAXN];
ll lazy[4*MAXN];
int n;

void build(int no,int i,int j){
  if(i==j){
    tree[no] = a[i] - (n-i);
 //   cout<<"INI "<<i<<" "<<tree[no]<<endl;
  }else{
    int m = (i+j)/2;
    int l = 2*no,r=2*no+1;
    build(l,i,m);
    build(r,m+1,j);
    tree[no] = max(tree[l],tree[r]);
  }
}

void propagate(int no,int i,int j){
  if(lazy[no]==0)return;
  tree[no]+=lazy[no];
  if(i!=j){
    lazy[2*no]+=lazy[no];
    lazy[2*no+1]+=lazy[no];
  }
  lazy[no] = 0;
}

void update(int no,int i,int j,int a,int b,int v){
  propagate(no,i,j);
  if(a>b)return;
  if(i>b || j<a || i>j)return;
  if(a<=i && j<=b){
    tree[no] += v;
    if(i!=j){
      lazy[2*no]+=v;
      lazy[2*no+1]+=v;
    }
    return;
  }
  int m = (i+j)/2;
  int l = 2*no,r=2*no+1;
  update(l,i,m,a,b,v);
  update(r,m+1,j,a,b,v);
  tree[no] = max(tree[l],tree[r]);
}

int query(int no,int i,int j){
  propagate(no,i,j);
  if(i==j)return i;
  int m = (i+j)/2;
  int l = 2*no,r=2*no+1;
  propagate(2*no,i,j);
  propagate(2*no+1,i,j);
  if(tree[l] >= tree[r])return query(l,i,m);
  return query(r,m+1,j);
}

int query2(int no,int i,int j,int a,int b){
  if(i>b || j<a || i>j)return 1e15;

  propagate(no,i,j);

  if(a<=i && j<=b)return tree[no];

  int m = (i+j)/2;
  int l = 2*no,r=2*no+1;

  return min(query2(l,i,m,a,b),query2(r,m+1,j,a,b));
}

int b[N];
// long long ?
int32_t main(){
  fastio;
  cin>>n;
  //node ini;
  //ini.x=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  build(1,1,n);

  for(int i=n;i>=1;i--){
    int pos = query(1,1,n);

    b[i] = query2(1,1,n,pos,pos);
 //   if(pos < i)b[i]+=n-i;
  //  else b[i]+=n-pos;

    update(1,1,n,1,n,1);
    update(1,1,n,pos,pos,-1e15);
  }
  int mn = 1e9;
  for(int i=n;i>=1;i--){
    if(b[i] > mn){
      cout<<":("<<endl;
      return 0;
    }
    mn = min(mn,b[i]);
  }
  for(int i=1;i<=n;i++){
    cout<<b[i]<<" ";
  }
  cout<<endl;

  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}


#include<bits/stdc++.h>
using namespace std;

const int N = 1e5+15;

bool can(string &s,int t){
	int n = s.size();
	int pos = 0;

	for(int i=0;i<s.size();++i){
		if(s[i]=='P'){
			pos = min(pos,i);
			while(pos<i){
				if(s[pos]=='*'){
					break;
				} else {
					++pos;
				}
			}
			int l = i-pos;

			if(l>t){
				return false;
			}

			int r = max(0, t-2*l);

			r = max(r, (t-l)/2 );

			pos = i + r + 1;
		}
	}

	while(pos<n){
		if(s[pos]=='*'){
			return false;
		} else {
			++pos;
		}
	}
	return true;
}
void solve(){
	int n;
	vector<int> in;
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		int a;
		scanf("%d",&a);
		in.push_back(a);
	}
	vector<pair<int,int> > tmp;
	for(int i=0;i<n;++i){
		tmp.push_back(make_pair(in[i]+i,i));
	}
	int cur =0;
	sort(tmp.begin(),tmp.end());
	int maxi = 0;
	vector<int> ret;
	for(int i=0;i<tmp.size();++i){
		int u;
		if(i==0){
			maxi = tmp[i].first;
			u = tmp[i].first;
		} else {
			u = tmp[i].first+cur;
			if(maxi>u){
				cout<<":(\n";
				return;
			}
			maxi = u;
		}
		ret.push_back(u);
		--cur;
	}
	for(int i=0;i<ret.size();++i){
		printf("%d ",ret[i] );
	}
	putchar('\n');

}
int main(){
	//freopen("input.txt","r",stdin);
    solve();
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
int n,m;
ll a;
vector<int> b;
vector<int> p;

bool check(int v){
    int j = 0;
    ll o = a;
    if (v > m or n - v < 0)
        return false;
    for (int i = n - v;i < n;i++)
    {
        int k = b[i] - p[j];
        if (k < 0){
            o += k;
        }
        if (o < 0)
            return false;
        j++;
    }
    return true;
}

int main()
{
    fast_io;
    cin >> n >> m >> a;
    int tmp;
    for (int i = 0;i < n;i++){
        cin >> tmp;
        b.push_back(tmp);
    }
    for (int i = 0;i < m;i++){
        cin >> tmp;
        p.push_back(tmp);
    }
    sort(all(b));
    sort(all(p));
    int l,mid,r;
    l = 0;
    r = MAXN;
    while (r-l > 1) {
        mid = (l + r) / 2;
        if (check(mid)){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    for (int i = 0;i < l;i++){
        a -= p[i];
    }
    a *= -1;
    if (a < 0)
        a = 0;
    cout << l << sep << a;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
int n;
int arr[MAXN];

int main()
{
    cin >> n;
    for (int i = 0;i < n;i++){
        arr[i] = i;
    }
    int tmp;
    for (int i = 0;i < n;i++){
        cin >> tmp;
        arr[i] += tmp;
    }
    sort(arr,arr+n);
    for (int i = 0;i < n;i++){
        arr[i] -= i;
    }
    int mn = 0;
    for (int i = 0;i < n;i++){
        if (arr[i] < mn){
            cout << ":(";
            return 0;
        }
        else{
            mn = arr[i];
        }
    }
    for (int i = 0; i < n;i++){
        cout << arr[i] << sep;
    }
}


#include<bits/stdc++.h>

using namespace std;
const int maxn=2e5+5;
int a[maxn];
bool flag=0;
unordered_map<int,int>v;
int main(){
    int n,x;
    scanf("%d",&n);
    v.clear();
    for(int i=1;i<=n;++i){
        scanf("%d",&x);
        a[i]=x+i;
        if(!v[x+i])v[x+i]=1;
        else flag=1;
    }
    if(flag)puts(":(");
    else{
        sort(a+1,a+1+n);
        for(int i=1;i<n;++i)printf("%d ",a[i]-i);
        printf("%d\n",a[n]-n);
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, v[200002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i], v[i] += i;
    sort(v+1, v+n+1);
    for(int i = 1; i <= n; ++i)
        v[i] -= i;
    for(int i = 2; i <= n; ++i)
        if(v[i-1] > v[i])
        {
            cout << ":(";
            return 0;
        }
    for(int i = 1; i <= n; ++i)
        cout << v[i] << " ";
    return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int n, w[201000], ck;
int main(){
    int i;
    scanf("%d", &n);
    for (i = 1; i <= n; i++){
        scanf("%d", &w[i]);
        w[i] += i;
    }
    sort(w + 1, w + n + 1);
    for (i = 1; i <= n; i++){
        w[i] -= i;
        if (i > 1 && w[i] < w[i - 1])ck = 1;
    }
    if (ck)printf(":(\n");
    else{
        for (i = 1; i <= n; i++)printf("%d ", w[i]);
    }
}


#include <bits/stdc++.h>
using namespace std;

#define   f(i,n) 			for(i=0;i<(n);i++)
#define   ff(i,n) 			for( i=1;i<=(n);i++)
#define   m0(X) 			memset((X), 0, sizeof((X)))
#define   m1(X) 			memset((X), -1, sizeof((X)))
#define   pb(x) 			push_back(x)
#define   mx 				1000 * 1000 * 1000 + 7

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1e18;

void rd(int &x){scanf("%d",&x);}
void rd(ll &x){scanf("%lld",&x);}
void rd(double &x){scanf("%lf",&x);}
void rd(int &x,int &y){scanf("%d%d",&x,&y);}
void rd(ll &x,ll &y){scanf("%lld%lld",&x,&y);}

void rd(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void rd(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}

void rd(double &x,double &y){scanf("%lf%lf",&x,&y);}
void rd(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void rd(char *s){scanf("%s",s);}
void rd(char &s){scanf("%c",&s);}
void rd(string &s){getline(cin,s);}

void pf(int x) {printf("%d\n",x);}
void pf(int x,int y) {printf("%d %d\n",x,y);}
void pf(ll x) {printf("%lld\n",x);}
void pf(char x) {printf("%c\n",x);}
void pf(char *x) {printf("%s\n",x);}
void pf(string x) {cout<<x<<endl;}

int main()
{
	ll n,i=1,j,p;
	rd(n);
	ll a[n];
	f(i,n) rd(a[i]);
	f(i,1234567){
		for(p=0;p<n-1;p++){
			if(a[p+1]<a[p]) break;
		}
		if(p==n-1) break;
		for(j=0;j<n-1;j++){
			if(a[j]-a[j+1]==1){
				cout<<":(\n";
				return 0;
			}

			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);
				a[j]++;
				a[j+1]--;
			}
		}
	}
	f(i,n) cout<<a[i]<<" ";
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define   f(i,n) 			for(i=0;i<(n);i++)
#define   ff(i,n) 			for( i=1;i<=(n);i++)
#define   m0(X) 			memset((X), 0, sizeof((X)))
#define   m1(X) 			memset((X), -1, sizeof((X)))
#define   pb(x) 			push_back(x)
#define   mx 				1000 * 1000 * 1000 + 7

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1e18;

void rd(int &x){scanf("%d",&x);}
void rd(ll &x){scanf("%lld",&x);}
void rd(double &x){scanf("%lf",&x);}
void rd(int &x,int &y){scanf("%d%d",&x,&y);}
void rd(ll &x,ll &y){scanf("%lld%lld",&x,&y);}

void rd(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void rd(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}

void rd(double &x,double &y){scanf("%lf%lf",&x,&y);}
void rd(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void rd(char *s){scanf("%s",s);}
void rd(char &s){scanf("%c",&s);}
void rd(string &s){getline(cin,s);}

void pf(int x) {printf("%d\n",x);}
void pf(int x,int y) {printf("%d %d\n",x,y);}
void pf(ll x) {printf("%lld\n",x);}
void pf(char x) {printf("%c\n",x);}
void pf(char *x) {printf("%s\n",x);}
void pf(string x) {cout<<x<<endl;}

int main()
{
	ll n,i=1,j,p;
	rd(n);
	ll a[n];
	f(i,n) rd(a[i]);
	f(i,12345678){
		for(p=0;p<n-1;p++){
			if(a[p+1]<a[p]) break;
		}
		if(p==n) break;
		for(j=0;j<n-1;j++){
			if(a[j]-a[j+1]==1){
				cout<<":(\n";
				return 0;
			}

			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);
				a[j]++;
				a[j+1]--;
			}
		}
	}
	f(i,n) cout<<a[i]<<" ";
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define   f(i,n) 			for(i=0;i<(n);i++)
#define   ff(i,n) 			for( i=1;i<=(n);i++)
#define   m0(X) 			memset((X), 0, sizeof((X)))
#define   m1(X) 			memset((X), -1, sizeof((X)))
#define   pb(x) 			push_back(x)
#define   mx 				1000 * 1000 * 1000 + 7

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1e18;

void rd(int &x){scanf("%d",&x);}
void rd(ll &x){scanf("%lld",&x);}
void rd(double &x){scanf("%lf",&x);}
void rd(int &x,int &y){scanf("%d%d",&x,&y);}
void rd(ll &x,ll &y){scanf("%lld%lld",&x,&y);}

void rd(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void rd(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}

void rd(double &x,double &y){scanf("%lf%lf",&x,&y);}
void rd(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void rd(char *s){scanf("%s",s);}
void rd(char &s){scanf("%c",&s);}
void rd(string &s){getline(cin,s);}

void pf(int x) {printf("%d\n",x);}
void pf(int x,int y) {printf("%d %d\n",x,y);}
void pf(ll x) {printf("%lld\n",x);}
void pf(char x) {printf("%c\n",x);}
void pf(char *x) {printf("%s\n",x);}
void pf(string x) {cout<<x<<endl;}

int main()
{
	ll n,i,j;
	rd(n);
	ll a[n];
	f(i,n) rd(a[i]);
	f(i,n-1){
		for(j=i;j<n-1;j++){
			if(a[j]-a[j+1]==1){
				cout<<":(\n";
				return 0;
			}

			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);
				a[j]++;
				a[j+1]--;
			}
		}
	}
	f(i,n) cout<<a[i]<<" ";
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define   f(i,n) 			for(i=0;i<(n);i++)
#define   ff(i,n) 			for( i=1;i<=(n);i++)
#define   m0(X) 			memset((X), 0, sizeof((X)))
#define   m1(X) 			memset((X), -1, sizeof((X)))
#define   pb(x) 			push_back(x)
#define   mx 				1000 * 1000 * 1000 + 7

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1e18;

void rd(int &x){scanf("%d",&x);}
void rd(ll &x){scanf("%lld",&x);}
void rd(double &x){scanf("%lf",&x);}
void rd(int &x,int &y){scanf("%d%d",&x,&y);}
void rd(ll &x,ll &y){scanf("%lld%lld",&x,&y);}

void rd(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void rd(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}

void rd(double &x,double &y){scanf("%lf%lf",&x,&y);}
void rd(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void rd(char *s){scanf("%s",s);}
void rd(char &s){scanf("%c",&s);}
void rd(string &s){getline(cin,s);}

void pf(int x) {printf("%d\n",x);}
void pf(int x,int y) {printf("%d %d\n",x,y);}
void pf(ll x) {printf("%lld\n",x);}
void pf(char x) {printf("%c\n",x);}
void pf(char *x) {printf("%s\n",x);}
void pf(string x) {cout<<x<<endl;}

int main()
{
	ll n,i=1,j,p;
	rd(n);
	ll a[n];
	f(i,n) rd(a[i]);
	f(i,1234567){
		for(p=0;p<n-1;p++){
			if(a[p+1]<a[p]) break;
		}
		if(p==n) break;
		for(j=0;j<n-1;j++){
			if(a[j]-a[j+1]==1){
				cout<<":(\n";
				return 0;
			}

			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);
				a[j]++;
				a[j+1]--;
			}
		}
	}
	f(i,n) cout<<a[i]<<" ";
	cout<<"\n";

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+5,INF=1e9+5;
int read(){
    char c=getchar();int x=0,f=1;
    while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();}
    return x*f;
}
int n,a[N];
int main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=read()-(n-i);
    sort(a+1,a+1+n);
    for(int i=1;i<n;i++) if(a[i]+n-i>a[i+1]+n-i-1){printf(":(");return 0;}
    for(int i=1;i<=n;i++) printf("%d ",a[i]+n-i);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+5,INF=1e9+5;
int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}
int n,a[N];
int main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=read()-(n-i);
    sort(a+1,a+1+n);
    for(int i=1;i<n;i++) if(a[i]+n-i>a[i+1]+n-i-1){printf(":(");return 0;}
    for(int i=1;i<=n;i++) printf("%d ",a[i]+n-i);
}


#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
long long M = 1e9 + 7;
#define int long long
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

const int N = 2e5 + 7;

int a[N];
int n;
int res[N];
set <pair <int, int> > s;
int32_t main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s.insert({-1 * (a[i] - (n - i)), i});
	}
	int lim = 1e18, pls = 0;
	for (int i = n; i >= 1; i--) {
		int t = -s.begin()->first + pls;
		if (t > lim) {
			cout << ":(";
			return 0;
		}
		lim = min(lim, t);
		res[i] = t;
		s.erase(s.begin());
		pls++;
	}
	for (int i = 1; i <= n; i++)
		cout << res[i] << " ";

	return 0;
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
for(ll i=1;i<=200;i++)
    v[i].clear();
for(ll i=1;i<=n;i++)
{
    scanf("%lld",&a[i]);
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    ll val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].size()==0){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,max((l+1)*2,(l+1)*2+it2-it1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<'\n';
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=200;i++)
    v[i].clear();
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    ll val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].size()==0){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,max((l+1)*2,(l+1)*2+it2-it1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
{
    scanf("%lld",&a[i]);
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(!v[x].empty()){
    ll l=0,r=v[x].size()-1;
    ll val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].empty()){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,max((l+1)*2,(l+1)*2+it2-it1));
        }
        l++;
        r--;
    }
        }
    x++;
}
printf("%lld\n",ans);
for(ll i=1;i<=200;i++)
    v[i].clear();
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
for(ll j=1;j<=200;j++)
{
    if(i!=1){
}else {
v[j].clear();
}
}
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(v[i].size()!=0){
           auto it1=lower_bound(v[i].begin(),v[i].end(),v[x][l]+1);
           auto it2=lower_bound(v[i].begin(),v[i].end(),v[x][r]-1);
           if(it1!=v[i].end()&&it2!=v[i].end()){
           if(*it2>=v[x][r]){
            *it2--;
           }
           s1=(it2-it1)+1;
           }
           }
           ans=max(ans,max((l+1)*2,(l+1)*2+s1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=200;i++)
    v[i].clear();
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    ans=max(ans,v[x].size());
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].size()==0){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,max((l+1)*2,(l+1)*2+it2-it1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=200;i++)
    v[i].clear();
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    ll val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].size()==0){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,max((l+1)*2,(l+1)*2+it2-it1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<'\n';
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
for(ll j=1;j<=200;j++)
{
    if(i!=1){
}else {
v[j].clear();
}
}
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x){
            continue;
           }
           if(v[i].size()!=0){
           auto it1=lower_bound(v[i].begin(),v[i].end(),v[x][l]+1);
           auto it2=lower_bound(v[i].begin(),v[i].end(),v[x][r]-1);
           if(it1!=v[i].end()&&it2!=v[i].end()){
           if(*it2>v[x][r]){
            *it2--;
           }
           s1=(it2-it1)+1;
           }
           }
           ans=max(ans,max((l+1)*2,(l+1)*2+s1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int t,n,a[200005];
vector<int>v[205];
int32_t main(){
CODE_START;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
    scanf("%d",&a[i]);
v[a[i]].pb(i);
}
int x=1;
int ans=1;
while(x<=200){
        if(!v[x].empty()){
    int l=0,r=v[x].size()-1;
    int val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(int i=1;i<=200;i++)
        {
           int s1=0;
           if(i==x||v[i].empty()){
            continue;
           }
           int it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           int it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,(l+1)*2+it2-it1);
        }
        l++;
        r--;
    }
        }
    x++;
}
printf("%d\n",ans);
for(int i=1;i<=200;i++)
    v[i].clear();
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
map<ll,ll>cnt[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=200;i++){
            cnt[i].clear();
v[i].clear();
}
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
for(ll j=1;j<=200;j++)
{
    cnt[j][i]=cnt[j][i-1];
}
cnt[a[i]][i]++;
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ans=max(ans,(l+1)*2+cnt[i][v[x][r]-1]-cnt[i][v[x][l]]);
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
for(ll j=1;j<=200;j++)
{
    if(i!=1){
}else {
v[j].clear();
}
}
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(v[i].size()!=0){
           auto it1=lower_bound(v[i].begin(),v[i].end(),v[x][l]+1);
           auto it2=lower_bound(v[i].begin(),v[i].end(),v[x][r]);
           if(it1!=v[i].end()&&it2!=v[i].end()){
           if(*it2>=v[x][r]){
            *it2--;
           }
           s1=(it2-it1)+1;
           }
           }
           ans=max(ans,max((l+1)*2,(l+1)*2+s1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
{
    scanf("%lld",&a[i]);
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    ll val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].size()==0){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,max((l+1)*2,(l+1)*2+it2-it1));
        }
        l++;
        r--;
    }
        }
    x++;
}
printf("%lld\n",ans);
for(ll i=1;i<=200;i++)
    v[i].clear();
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
{
    scanf("%lld",&a[i]);
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(!v[x].empty()){
    ll l=0,r=v[x].size()-1;
    ll val=v[x].size();
    ans=max(ans,val);
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(i==x||v[i].empty()){
            continue;
           }
           ll it1=lower_bound(v[i].begin(),v[i].end(),v[x][l])-v[i].begin();
           ll it2=lower_bound(v[i].begin(),v[i].end(),v[x][r])-v[i].begin();
           ans=max(ans,(l+1)*2+it2-it1);
        }
        l++;
        r--;
    }
        }
    x++;
}
printf("%lld\n",ans);
for(ll i=1;i<=200;i++)
    v[i].clear();
}
}


#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[200005];
vector<ll>v[205];
int32_t main(){
CODE_START;
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
for(ll j=1;j<=200;j++)
{
    if(i!=1){
}else {
v[j].clear();
}
}
v[a[i]].pb(i);
}
ll x=1;
ll ans=1;
while(x<=200){
        if(v[x].size()!=0){
    ll l=0,r=v[x].size()-1;
    while(l<r){
        for(ll i=1;i<=200;i++)
        {
           ll s1=0;
           if(v[i].size()!=0){
           auto it1=lower_bound(v[i].begin(),v[i].end(),v[x][l]+1);
           auto it2=lower_bound(v[i].begin(),v[i].end(),v[x][r]-1);
           if(it1!=v[i].end()&&it2!=v[i].end()){
           if(*it2>v[x][r]){
            *it2--;
           }
           s1=(it2-it1)+1;
           }
           }
           ans=max(ans,max((l+1)*2,(l+1)*2+s1));
        }
        l++;
        r--;
    }
        }
    x++;
}
cout<<ans<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(i == j){
					ans = max(ans, count[i]);
				}
				else{
					vector<int> temp;
					for(int c=0; c<n; c++){
						if(arr[c] == i){
							temp.push_back(0);
						}
						if(arr[c] == j){
							temp.push_back(1);
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<200; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		//cout << "a" << endl;
		for(int i=0; i<200; i++){
			for(int j=0; j<200; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, (int)occur[i].size()-1);
					continue;
				}
				else{
					int s = 0;
					vector<int> temp;
					for(int a=0, b=0; a<occur[i].size()-1||b<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							a++;
						}
						else{
							s++;
							temp.push_back(1);
							b++;
						}
					}
		//			for(int ll=0; ll<temp.size(); ll++){
		//				cout << temp[ll] << " ";
		//			}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(i == j){
					ans = max(ans, count[i]);
				}
				else{
					vector<int> temp;
					for(int c=0; c<n; c++){
						if(arr[c] == i){
							temp.push_back(0);
						}
						if(arr[c] == j){
							temp.push_back(1);
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<n; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, count[i]);
					continue;
				}
				else{
					vector<int> temp;
					for(int a=0, b=0; i<occur[i].size()-1||occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							i++;
						}
						else{
							temp.push_back(1);
							j++:
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(i == j){
					ans = max(ans, count[i]);
				}
				else{
					vector<int> temp;
					for(int c=0; c<n; c++){
						if(arr[c] == i){
							temp.push_back(0);
						}
						if(arr[c] == j){
							temp.push_back(1);
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			occur[a-1].push_back(i);
		}
		for(int i=0; i<200; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		//cout << "a" << endl;
		for(int i=0; i<200; i++){
			for(int j=0; j<200; j++){
				if(occur[i].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, (int)occur[i].size()-1);
					continue;
				}
				else{
					int s = 0;
					vector<int> temp;
					for(int a=0, b=0; a<occur[i].size()-1||b<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							a++;
						}
						else{
							s++;
							temp.push_back(1);
							b++;
						}
					}
		//			for(int ll=0; ll<temp.size(); ll++){
		//				cout << temp[ll] << " ";
		//			}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<n; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, count[i]);
					continue;
				}
				else{
					vector<int> temp;
					for(int a=0, b=0; a<occur[i].size()-1||b<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							a++;
						}
						else{
							temp.push_back(1);
							b++;
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<200; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		//cout << "a" << endl;
		for(int i=0; i<200; i++){
			for(int j=0; j<200; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, count[i]);
					continue;
				}
				else{
					vector<int> temp;
					for(int a=0, b=0; a<occur[i].size()-1||b<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							a++;
						}
						else{
							temp.push_back(1);
							b++;
						}
					}
		//			for(int ll=0; ll<temp.size(); ll++){
		//				cout << temp[ll] << " ";
		//			}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<vector<int>> occur(200);
		vector<int> temp;
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			occur[a-1].push_back(i);
		}
		for(int i=0; i<200; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		//cout << "a" << endl;
		for(int i=0; i<200; i++){
			for(int j=0; j<200; j++){
				if(occur[i].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, (int)occur[i].size()-1);
					continue;
				}
				else{
					int s = 0;
					for(int a=0, b=0; a<occur[i].size()-1||b<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							a++;
						}
						else{
							s++;
							temp.push_back(1);
							b++;
						}
					}
		//			for(int ll=0; ll<temp.size(); ll++){
		//				cout << temp[ll] << " ";
		//			}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
					temp.clear();
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<n; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, count[i]);
					continue;
				}
				else{
					vector<int> temp;
					for(int a=0, b=0; i<occur[i].size()-1||occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							i++;
						}
						else{
							temp.push_back(1);
							j++;
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		map<int, int> count;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			count[a]++;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<n; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		for(int i=1; i<201; i++){
			for(int j=1; j<201; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, count[i]);
					continue;
				}
				else{
					vector<int> temp;
					for(int a=0, b=0; i<occur[i].size()-1||j<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							i++;
						}
						else{
							temp.push_back(1);
							j++;
						}
					}
					int s = 0;
					for(int m : temp){
						s += m;
					}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> arr;
		vector<vector<int>> occur(200);
		for(int i=0; i<n; i++){
			int a;
			cin >> a;
			arr.push_back(a);
			occur[a-1].push_back(i);
		}
		for(int i=0; i<200; i++){
			occur[i].push_back(n);
		}
		int ans = 0;
		//cout << "a" << endl;
		for(int i=0; i<200; i++){
			for(int j=0; j<200; j++){
				if(occur[j].size() == 1){
					continue;
				}
				if(i == j){
					ans = max(ans, occur[i].size()-1);
					continue;
				}
				else{
					int s = 0;
					vector<int> temp;
					for(int a=0, b=0; a<occur[i].size()-1||b<occur[j].size() - 1;){
						if(occur[i][a] < occur[j][b]){
							temp.push_back(0);
							a++;
						}
						else{
							s++;
							temp.push_back(1);
							b++;
						}
					}
		//			for(int ll=0; ll<temp.size(); ll++){
		//				cout << temp[ll] << " ";
		//			}
					int l = 0, r = temp.size() - 1, x = 0;
					ans = max(ans, s);
					while(true){
						x++;
						bool bl = 0, br = 0;
						while(l<=r and !bl){
							if(temp[l] == 0){
								bl = 1;
							}
							else{
								s--;
							}

								l++;
						}
						while(r>=l and !br){
							if(temp[r] == 0){
								br = 1;
							}
							else{
								s--;
							}
							r--;
						}
						if(!bl or !br){
							break;
						}
						ans = max(ans, 2*x + s);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
//#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

map<int,int> mp;
struct cmp
{
	bool operator()(const int & a, const int & b)const
	{
		return make_pair(mp[a],a)>make_pair(mp[b],b);
	}
};
int solve(int num , vector<int> inp)
{
	mp.clear();
	int n=inp.size();
	int pres=0;
	map<int,int> pref,suff;
	for(int i=0;i<n;++i)
	{
		if(inp[i]==num)
		{
			++pres;
			pref[pres]=i;
		}
	}
	pres=0;
	for(int i=n-1;i>=0;--i)
	{
		if(inp[i]==num)
		{
			++pres;
			suff[pres]=i;
		}
	}

	int lft=0,rgt=n-1;
	for(int i=0;i<n;++i)
	{
		++mp[inp[i]];
	}
	set<int,cmp> st;
	for(auto it:inp)
	{
		st.insert(it);
	}
	int ans=pres;
	for(int i=1;i<=pres;++i)
	{
		int lpoint=pref[i];
		int rpoint=suff[i];
		if(rpoint<=lpoint){break;}
		else
		{
			++lpoint;
			while(lft<lpoint)
			{
				st.erase(inp[lft]);
				--mp[inp[lft]];
				st.insert(inp[lft]);
				++lft;
			}
			--rpoint;
			while(rpoint<rgt)
			{
				st.erase(inp[rgt]);
				--mp[inp[rgt]];
				st.insert(inp[rgt]);
				--rgt;
			}
			int tot=mp[*st.begin()];
			ans=max(ans,tot+2*i);
		}
	}
	return ans;

}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		//cout<<n<<"-----\n";
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		int ans=0;
		for(int i=1;i<=200;++i)///change this
		{
			ans=max(ans,solve(i,inp));
		}
		cout<<ans<<"\n";
	}
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		vector<int> next(n),tot(n);
		for(int num=1;num<=200;++num)
		{

			int pres=0;
			vector<int> revsuffix(n+1);
			for(int i=n-1;i>=0;--i)
			{
				if(inp[i]==num){
					++pres;
					revsuffix[pres]=i;
				}
				else
				{
				}
			}
			pres=0;
			for(int i=0;i<n;++i)
			{
				if(inp[i]==num){
					++pres;
					tot[i]=pres;
					int lft=i;
					int rgt=revsuffix[pres];
					next[lft]=rgt;
				}
			}
		}
		int ans=0;
		for(int centre=1;centre<201;++centre)
		{
			int pres=0;
			std::vector<int> psum(n);
			for(int i=0; i<n;++i)
			{
				pres+=inp[i]==centre;
				psum[i]=pres;
			}
			ans=max(ans,pres);
			for(int lft=0;lft<n;++lft)
			{
				int rgt=next[lft];
				if(rgt<=lft){continue;}
				ans=max(2*tot[lft]+(psum[rgt-1]-psum[lft]),ans);
			}
		}
		cout<<ans<<"\n";
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<int> mp;
struct cmp
{
	bool operator()(const int & a, const int & b)const
	{
		return make_pair(mp[a],a)>make_pair(mp[b],b);
	}
};
int solve(int num , vector<int> inp)
{
	mp.assign(205,0);
	int n=inp.size();
	int pres=0;
	vector<int> pref(n+1,0),suff(n+1,0);
	for(int i=0;i<n;++i)
	{
		if(inp[i]==num)
		{
			++pres;
			pref[pres]=i;
		}
	}
	if(pres==0){return 0;}
	pres=0;
	for(int i=n-1;i>=0;--i)
	{
		if(inp[i]==num)
		{
			++pres;
			suff[pres]=i;
		}
	}

	int lft=0,rgt=n-1;
	for(int i=0;i<n;++i)
	{
		++mp[inp[i]];
	}
	set<int,cmp> st;
	for(auto it:inp)
	{
		st.insert(it);
	}
	int ans=pres;
	for(int i=1;i<=pres;++i)
	{
		int lpoint=pref[i];
		int rpoint=suff[i];
		if(rpoint<=lpoint){break;}
		else
		{
			++lpoint;
			while(lft<lpoint)
			{
				st.erase(inp[lft]);
				--mp[inp[lft]];
				st.insert(inp[lft]);
				++lft;
			}
			--rpoint;
			while(rpoint<rgt)
			{
				st.erase(inp[rgt]);
				--mp[inp[rgt]];
				st.insert(inp[rgt]);
				--rgt;
			}
			int tot=mp[*st.begin()];
			ans=max(ans,tot+2*i);
		}
	}
	return ans;

}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		//cout<<n<<"-----\n";
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		int ans=0;
		for(int i=1;i<=200;++i)///change this
		{
			ans=max(ans,solve(i,inp));
		}
		cout<<ans<<"\n";
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<int> mp;
bool cmp1(int a, int b)
{
	return mp[a]>mp[b];
}
int solve(int num , vector<int> inp)
{
	mp.assign(205,0);
	int n=inp.size();
	int pres=0;
	vector<int> pref(n+1,0),suff(n+1,0);
	for(int i=0;i<n;++i)
	{
		++mp[inp[i]];
		if(inp[i]==num)
		{
			++pres;
			pref[pres]=i;
		}
	}
	if(pres==0){return 0;}
	pres=0;
	for(int i=n-1;i>=0;--i)
	{
		if(inp[i]==num)
		{
			++pres;
			suff[pres]=i;
		}
	}

	int lft=0,rgt=n-1;
	set<int> tst;for(auto it:inp){tst.insert(it);}
	vector<int> st;
	for(auto it:tst)
	{
		st.push_back(it);
	}
	sort(st.begin(),st.end(),cmp1);

	std::vector<int> rev(205,0);
	for(int i=0;i<st.size();++i)
	{
		rev[st[i]]=i;
	}
	int ans=pres;
	for(int i=1;i<=pres;++i)
	{
		int lpoint=pref[i];
		int rpoint=suff[i];
		if(rpoint<=lpoint){break;}
		else
		{
			++lpoint;
			while(lft<lpoint)
			{
				int pos=rev[inp[lft]];
				--mp[inp[lft]];
				if(pos!=st.size()-1 and mp[inp[lft]]<mp[st[pos+1]])
				{
					int tmp=inp[lft];
					st[pos]=st[pos+1];
					st[pos+1]=tmp;
				}
				++lft;
			}
			--rpoint;
			while(rpoint<rgt)
			{
				int pos=rev[inp[rgt]];
				--mp[inp[rgt]];
				if(pos!=st.size()-1 and mp[inp[rgt]]<mp[st[pos+1]])
				{
					int tmp=inp[rgt];
					st[pos]=st[pos+1];
					st[pos+1]=tmp;
				}
				--rgt;
			}
			int tot=mp[*st.begin()];
			ans=max(ans,tot+2*i);
		}
	}
	return ans;

}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		//cout<<n<<"-----\n";
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		int ans=0;
		for(int i=1;i<=200;++i)///change this
		{
			ans=max(ans,solve(i,inp));
		}
		cout<<ans<<"\n";
	}
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<vector<int>> prefix(201,vector<int>(200005));
vector<vector<int>> revsuffix(200005,vector<int>(201));
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		for(int num=1;num<=200;++num)
		{
			int pres=0;
			for(int i=0;i<n;++i)
			{
				if(inp[i]==num){
					++pres;
					prefix[num][i]=pres;
				}
				else
				{
					prefix[num][i]=pres;
				}

			}
			pres=0;
			for(int i=n-1;i>=0;--i)
			{
				if(inp[i]==num){
					++pres;
					revsuffix[num][pres]=i;
				}
				else
				{
				}
			}
		}
		int ans=0;
		for(int centre=1;centre<201;++centre)
		{
			int pres=0;
			std::vector<int> psum(n);
			for(int i=0; i<n;++i)
			{
				pres+=inp[i]==centre;
				psum[i]=pres;
			}
			ans=max(ans,pres);
			for(int lft=0;lft<n;++lft)
			{
				int rgt=revsuffix[inp[lft]][prefix[inp[lft]][lft]];
				if(rgt<=lft){continue;}
				ans=max(2*prefix[inp[lft]][lft]+(psum[rgt-1]-psum[lft]),ans);
			}
		}
		cout<<ans<<"\n";
	}
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		vector<vector<int> > prefix,suffix(201,vector<int>(n));
		prefix=suffix;
		vector<vector<int>> revprefix(201,vector<int> (n+1)),revsuffix;
		revsuffix=revprefix;
		for(int num=1;num<=200;++num)
		{
			int pres=0;
			for(int i=0;i<n;++i)
			{
				if(inp[i]==num){
					++pres;
					prefix[num][i]=pres;
					revprefix[num][pres]=i;
				}
				else
				{
					prefix[num][i]=pres;
				}

			}
			pres=0;
			for(int i=n-1;i>=0;--i)
			{
				if(inp[i]==num){
					++pres;
					suffix[num][i]=pres;
					revsuffix[num][pres]=i;
				}
				else
				{
					suffix[num][i]=pres;
				}
			}
		}
		int ans=0;
		for(int centre=1;centre<201;++centre)
		{
			int pres=0;
			std::vector<int> psum(n);
			for(int i=0; i<n;++i)
			{
				pres+=inp[i]==centre;
				psum[i]=pres;
			}
			ans=max(ans,pres);
			for(int lft=0;lft<n;++lft)
			{
				int rgt=revsuffix[inp[lft]][prefix[inp[lft]][lft]];
				if(rgt<=lft){continue;}
				ans=max(2*prefix[inp[lft]][lft]+(psum[rgt-1]-psum[lft]),ans);
			}
		}
		cout<<ans<<"\n";
	}
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<vector<int>> prefix(201,vector<int>(200005)),suffix(201,vector<int>(200005));
vector<vector<int>> revprefix(200005,vector<int>(201)),revsuffix(200005,vector<int>(201));
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		for(int num=1;num<=200;++num)
		{
			int pres=0;
			for(int i=0;i<n;++i)
			{
				if(inp[i]==num){
					++pres;
					prefix[num][i]=pres;
					revprefix[num][pres]=i;
				}
				else
				{
					prefix[num][i]=pres;
				}

			}
			pres=0;
			for(int i=n-1;i>=0;--i)
			{
				if(inp[i]==num){
					++pres;
					suffix[num][i]=pres;
					revsuffix[num][pres]=i;
				}
				else
				{
					suffix[num][i]=pres;
				}
			}
		}
		int ans=0;
		for(int centre=1;centre<201;++centre)
		{
			int pres=0;
			std::vector<int> psum(n);
			for(int i=0; i<n;++i)
			{
				pres+=inp[i]==centre;
				psum[i]=pres;
			}
			ans=max(ans,pres);
			for(int lft=0;lft<n;++lft)
			{
				int rgt=revsuffix[inp[lft]][prefix[inp[lft]][lft]];
				if(rgt<=lft){continue;}
				ans=max(2*prefix[inp[lft]][lft]+(psum[rgt-1]-psum[lft]),ans);
			}
		}
		cout<<ans<<"\n";
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<int> mp;
bool cmp1(int a, int b)
{
	return mp[a]>mp[b];
}
int solve(int num , vector<int> inp)
{
	mp.assign(205,0);
	int n=inp.size();
	int pres=0;
	vector<int> pref(n+1,0),suff(n+1,0);
	for(int i=0;i<n;++i)
	{
		++mp[inp[i]];
		if(inp[i]==num)
		{
			++pres;
			pref[pres]=i;
		}
	}
	if(pres==0){return 0;}
	pres=0;
	for(int i=n-1;i>=0;--i)
	{
		if(inp[i]==num)
		{
			++pres;
			suff[pres]=i;
		}
	}

	int lft=0,rgt=n-1;
	set<int> tst;for(auto it:inp){tst.insert(it);}
	vector<int> st;
	for(auto it:tst)
	{
		st.push_back(it);
	}
	sort(st.begin(),st.end(),cmp1);

	std::vector<int> rev(205,0);
	for(int i=0;i<st.size();++i)
	{
		rev[st[i]]=i;
	}
	int ans=pres;
	for(int i=1;i<=pres;++i)
	{
		int lpoint=pref[i];
		int rpoint=suff[i];
		if(rpoint<=lpoint){break;}
		else
		{
			++lpoint;
			while(lft<lpoint)
			{
				int pos=rev[inp[lft]];
				--mp[inp[lft]];
				if(pos!=(st.size()-1) and mp[inp[lft]]<mp[st[pos+1]])
				{
					int tmp=inp[lft];
					st[pos]=st[pos+1];
					st[pos+1]=tmp;
					rev[st[pos]]=pos;
					rev[st[pos+1]]=pos+1;
				}
				++lft;
			}
			--rpoint;
			while(rpoint<rgt)
			{
				int pos=rev[inp[rgt]];
				--mp[inp[rgt]];
				if(pos!=st.size()-1 and mp[inp[rgt]]<mp[st[pos+1]])
				{
					int tmp=inp[rgt];
					st[pos]=st[pos+1];
					st[pos+1]=tmp;
					rev[st[pos]]=pos;
					rev[st[pos+1]]=pos+1;
				}
				--rgt;
			}
			int tot=mp[*st.begin()];
			ans=max(ans,tot+2*i);
		}
	}
	return ans;

}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		//cout<<n<<"-----\n";
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		int ans=0;
		for(int i=1;i<=200;++i)///change this
		{
			ans=max(ans,solve(i,inp));
		}
		cout<<ans<<"\n";
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

map<int,int> mp;
struct cmp
{
	bool operator()(const int & a, const int & b)const
	{
		return make_pair(mp[a],a)>make_pair(mp[b],b);
	}
};
int solve(int num , vector<int> inp)
{
	mp.clear();
	int n=inp.size();
	int pres=0;
	map<int,int> pref,suff;
	for(int i=0;i<n;++i)
	{
		if(inp[i]==num)
		{
			++pres;
			pref[pres]=i;
		}
	}
	pres=0;
	for(int i=n-1;i>=0;--i)
	{
		if(inp[i]==num)
		{
			++pres;
			suff[pres]=i;
		}
	}

	int lft=0,rgt=n-1;
	for(int i=0;i<n;++i)
	{
		++mp[inp[i]];
	}
	set<int,cmp> st;
	for(auto it:inp)
	{
		st.insert(it);
	}
	int ans=pres;
	for(int i=1;i<=pres;++i)
	{
		int lpoint=pref[i];
		int rpoint=suff[i];
		if(rpoint<=lpoint){break;}
		else
		{
			++lpoint;
			while(lft<lpoint)
			{
				st.erase(inp[lft]);
				--mp[inp[lft]];
				st.insert(inp[lft]);
				++lft;
			}
			--rpoint;
			while(rpoint<rgt)
			{
				st.erase(inp[rgt]);
				--mp[inp[rgt]];
				st.insert(inp[rgt]);
				--rgt;
			}
			int tot=mp[*st.begin()];
			ans=max(ans,tot+2*i);
		}
	}
	return ans;

}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		//cout<<n<<"-----\n";
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		int ans=0;
		for(int i=1;i<=200;++i)///change this
		{
			ans=max(ans,solve(i,inp));
		}
		cout<<ans<<"\n";
	}
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

vector<vector<int>> prefix(201,vector<int>(200005)),suffix(201,vector<int>(200005));
vector<vector<int>> revprefix(200005,vector<int>(201)),revsuffix(200005,vector<int>(201));
//edge cases when n=1 , m=1. wrong variable in loop. if<->while;merge resize
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	speed
	//global var
	int tt;cin>>tt;
	while(tt--)
	{
		int n;cin>>n;
		std::vector<int> inp(n);
		for (int i = 0; i < n; ++i)
		{
			cin>>inp[i];
		}
		for(int num=1;num<=200;++num)
		{
			int pres=0;
			for(int i=0;i<n;++i)
			{
				if(inp[i]==num){
					++pres;
					prefix[num][i]=pres;
					revprefix[num][pres]=i;
				}
				else
				{
					prefix[num][i]=pres;
				}

			}
			pres=0;
			for(int i=n-1;i>=0;--i)
			{
				if(inp[i]==num){
					++pres;
					suffix[num][i]=pres;
					revsuffix[num][pres]=i;
				}
				else
				{
					suffix[num][i]=pres;
				}
			}
		}
		int ans=0;
		for(int centre=1;centre<201;++centre)
		{
			int pres=0;
			std::vector<int> psum(n);
			for(int i=0; i<n;++i)
			{
				pres+=inp[i]==centre;
				psum[i]=pres;
			}
			ans=max(ans,pres);
			for(int lft=0;lft<n;++lft)
			{
				int rgt=revsuffix[inp[lft]][prefix[inp[lft]][lft]];
				if(rgt<=lft){continue;}
				ans=max(2*prefix[inp[lft]][lft]+(psum[rgt-1]-psum[lft]),ans);
			}
		}
		cout<<ans<<"\n";
	}
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        ll pre[200][n];
        fo(i,200) pre[i][0] = 0;
        pre[a[0]-1][0] = 1;
        for(i=1;i<n;i++){
            fo(j,200){
                if(a[i]==j+1)
                    pre[j][i] = pre[j][i-1]+1;
                else
                    pre[j][i] = pre[j][i-1];
            }
        }
        /*fo(i,200){
            fo(j,n) cout<<pre[i][j]<<" ";
            cout<<endl;
        }*/
        //calc suffixes
        ll suf[200][n];
        fo(i,200) suf[i][n-1] = 0;
        suf[a[n-1]-1][n-1] = 1;
        //cout<<endl;
        for(i=n-2;i>=0;i--){
            for(j=0;j<200;j++){
                suf[j][i] = suf[j][i+1];
                if(a[i]==j+1)
                    suf[j][i] = suf[j][i]+1;
            }
        }

        ends_range er[200];

        fo(i,200){
            er[i].count = (suf[i][0]/2)*2;
            fo(j,n){
                if(pre[i][j]==1) er[i].ls = j;
                if(pre[i][j]== er[i].count/2){
                    er[i].le = j;
                    break;
                }
            }
        }
        fo(i,200){
            for(j=n-1;j>=0;j--){
                if(suf[i][j]==1) er[i].rs = j;
                if(suf[i][j]==er[i].count/2 and er[i].count!=0){
                    er[i].re = j;
                    break;
                }
            }
        }
        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;

        ll max_len = 1;
        fo(i,200){

            ll start = er[i].le;
            ll end = er[i].re;
            ll curr_count = er[i].count;
            while (start>=0 and end<=n-1)
            {

                ll count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                ll mx_count = 0;
                for(ll c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                //cout<<i+1<<" "<<start<<" "<<end<<" "<<mx_count<<endl;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        ll pre[200][n];
        fo(i,200) pre[i][0] = 0;
        pre[a[0]-1][0] = 1;
        for(i=1;i<n;i++){
            fo(j,200){
                if(a[i]==j+1)
                    pre[j][i] = pre[j][i-1]+1;
                else
                    pre[j][i] = pre[j][i-1];
            }
        }
        /*fo(i,200){
            fo(j,n) cout<<pre[i][j]<<" ";
            cout<<endl;
        }
        //calc suffixes
        ll suf[200][n];
        fo(i,200) suf[i][n-1] = 0;
        suf[a[n-1]-1][n-1] = 1;
        //cout<<endl;
        for(i=n-2;i>=0;i--){
            for(j=0;j<200;j++){
                suf[j][i] = suf[j][i+1];
                if(a[i]==j+1)
                    suf[j][i] = suf[j][i]+1;
            }
        }*/

        ends_range er[200];

        fo(i,200){
            er[i].count = (pre[i][n-1]/2)*2;
            fo(j,n){
                if(pre[i][j]==1) er[i].ls = j;
                if(pre[i][j]== er[i].count/2){
                    er[i].le = j;
                    break;
                }
            }
        }
        fo(i,200){
            for(j=n-1;j>0;j--){
                if(pre[i][j-1]==pre[i][n-1]-1) er[i].rs = j;
                if(pre[i][j-1]==ceil(pre[i][n-1]/2.0) and er[i].count!=0){
                    er[i].re = j;
                    break;
                }
            }
        }
        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;

        ll max_len = 1;
        fo(i,200){

            ll start = er[i].le;
            ll end = er[i].re;
            ll curr_count = er[i].count;
            while (start>=0 and end<=n-1)
            {

                ll count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                ll mx_count = 0;
                for(ll c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                //cout<<i+1<<" "<<start<<" "<<end<<" "<<mx_count<<endl;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


    #include<iostream>
    #include<string>
    #include<bits/stdc++.h>

    #define fo(i,n) for(i=0;i<n;i++)
    #define pb push_back

    using namespace std;

    typedef long long ll;
    typedef long l;
    typedef vector<int> vint;

    struct ends_range{
        ll count=0,ls=0,le=0,rs=0,re=0;
    };

    int main(){
        int T;
        cin>>T;
        for(int t=1;t<=T;t++){
            ll n,i,j;
            cin>>n;
            int a[n];
            fo(i,n) cin>>a[i];

            //calc prefixes
            ll pre[200][n];
            fo(i,200) pre[i][0]=0;
            pre[a[0]-1][0] = 1;
            ll count[200] = {0};
            for(i=0;i<n;i++){
                count[a[i]-1]+=1;
            }
            for(i=1;i<n;i++){
                fo(j,200) pre[j][i] = pre[j][i-1];
                pre[a[i]-1][i]++;
            }
            /*fo(i,200){
                fo(j,n) cout<<pre[i][j]<<" ";
                cout<<endl;
            }*/
            bool broke = false;
            fo(i,200){
                if(count[i]==n){
                    cout<<n<<endl;
                    broke = true;
                    break;
                }
            }
            if(broke) continue;
            ends_range er[200];

            fo(i,200){
                er[i].count = (count[i]/2)*2;
                ll cur_count = 0;
                fo(j,n){
                    if(a[j]==i+1){
                        cur_count++;
                        if(cur_count==1) er[i].ls = j;
                        if(cur_count==count[i]/2) er[i].le = j;
                        if(cur_count==ceil(count[i]/2.0)+1) er[i].re = j;
                        if(cur_count==count[i]){
                            er[i].rs = j;
                            break;
                        }
                    }
                }
            }

            //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
            ll max_len = 1;
            for(int m=0;m<200;m++){
                ll start = er[m].le;
                ll end = er[m].re;
                ll curr_count = er[m].count;
                //cout<<m+1<<" "<<start<<" "<<end<<endl;
                if(curr_count==0) continue;

                while (start>=0 and end<=n-1 ){
                    ll count[200] = {0};
                    if(start<end){
                        //cout<<i+1<<": ";
                        fo(i,200){
                            count[i]= pre[i][end-1]-pre[i][start];
                            //cout<<count[i]<<" ";
                        }
                        //cout<<endl;
                    }
                    ll mx_count = 0;
                    for(ll c: count) if(c>mx_count) mx_count=c;
                    if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                    if((start+1+n-end)<=curr_count) break;
                    curr_count -=2;
                    start--;
                    end ++;
                    while(start>=0 and a[start]!=i+1) start--;
                    while(end<=n-1 and a[end]!=i+1 ) end++;
                }
            }
            cout<<max_len<<endl;

        }
    }


    #include<iostream>
    #include<string>
    #include<bits/stdc++.h>

    #define fo(i,n) for(i=0;i<n;i++)
    #define pb push_back

    using namespace std;

    typedef long long ll;
    typedef long l;
    typedef vector<int> vint;

    struct ends_range{
        ll count=0,ls=0,le=0,rs=0,re=0;
    };

    int main(){
        int T;
        cin>>T;
        for(int t=1;t<=T;t++){
            ll n,i,j;
            cin>>n;
            int a[n];
            fo(i,n) cin>>a[i];

            //calc prefixes
            ll pre[200][n];
            fo(i,200) pre[i][0]=0;
            pre[a[0]-1][0] = 1;
            ll count[200] = {0};
            for(i=0;i<n;i++){
                count[a[i]-1]+=1;
            }
            for(i=1;i<n;i++){
                fo(j,200) pre[j][i] = pre[j][i-1];
                pre[a[i]-1][i]++;
            }
            /*fo(i,200){
                fo(j,n) cout<<pre[i][j]<<" ";
                cout<<endl;
            }*/
            bool broke = false;
            fo(i,200){
                if(count[i]==n){
                    cout<<n<<endl;
                    broke = true;
                    break;
                }
            }
            if(broke) continue;
            ends_range er[200];

            fo(i,200){
                er[i].count = (count[i]/2)*2;
                ll cur_count = 0;
                fo(j,n){
                    if(a[j]==i+1){
                        cur_count++;
                        if(cur_count==1) er[i].ls = j;
                        if(cur_count==count[i]/2) er[i].le = j;
                        if(cur_count==ceil(count[i]/2.0)+1) er[i].re = j;
                        if(cur_count==count[i]){
                            er[i].rs = j;
                            break;
                        }
                    }
                }
            }

            //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
            ll max_len = 1;
            fo(i,200){
                ll start = er[i].le;
                ll end = er[i].re;
                ll curr_count = er[i].count;
                while (start>=0 and end<=n-1 )
                {
                    ll count[200] = {0};
                    if(start+1<end){
                        fo(i,200){
                            count[i]= pre[i][end-1]-pre[i][start];
                            //cout<<count[i]<<endl;
                        }
                    }
                    ll mx_count = 0;
                    for(ll c: count) if(c>mx_count) mx_count=c;
                    if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                    if((start+1+n-end)<=curr_count) break;
                    curr_count -=2;
                    start--;
                    end ++;
                    while(a[start]!=i+1 and start>=0) start--;
                    while(a[end]!=i+1 and end<=n-1) end++;
                }
            }
            cout<<max_len<<endl;

        }
    }


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        ll count[200] = {0};
        for(i=0;i<n;i++){
            count[a[i]-1]+=1;
        }
        ends_range er[200];

        fo(i,200){
            er[i].count = (count[i]/2)*2;
            ll cur_count = 0;
            fo(j,n){
                if(a[j]==i+1){
                    cur_count++;
                    if(cur_count==1) er[i].ls = j;
                    if(cur_count==count[i]/2) er[i].le = j;
                    if(cur_count==ceil(count[i]/2.0)+1) er[i].re = j;
                    if(cur_count==count[i]){
                        er[i].rs = j;
                        break;
                    }
                }
            }
        }

        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
        ll max_len = 1;
        fo(i,200){
            ll start = er[i].le;
            ll end = er[i].re;
            ll curr_count = er[i].count;
            while (start>=0 and end<=n-1 )
            {

                ll count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                ll mx_count = 0;
                for(ll c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                if((start+1+n-end)<=curr_count) break;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        int pre[200][n];
        fo(i,200) pre[i][0] = 0;
        pre[a[0]-1][0] = 1;
        for(i=1;i<n;i++){
            fo(j,200){
                if(a[i]==j+1)
                    pre[j][i] = pre[j][i-1]+1;
                else
                    pre[j][i] = pre[j][i-1];
            }
        }
        /*fo(i,200){
            fo(j,n) cout<<pre[i][j]<<" ";
            cout<<endl;
        }*/
        //calc suffixes
        int suf[200][n];
        fo(i,200) suf[i][n-1] = 0;
        suf[a[n-1]-1][n-1] = 1;
        //cout<<endl;
        for(i=n-2;i>=0;i--){
            for(j=0;j<200;j++){
                suf[j][i] = suf[j][i+1];
                if(a[i]==j+1)
                    suf[j][i] = suf[j][i]+1;
            }
        }

        ends_range er[200];

        fo(i,200){
            er[i].count = (suf[i][0]/2)*2;
            fo(j,n){
                if(pre[i][j]==1) er[i].ls = j;
                if(pre[i][j]== er[i].count/2){
                    er[i].le = j;
                    break;
                }
            }
        }
        fo(i,200){
            for(j=n-1;j>=0;j--){
                if(suf[i][j]==1) er[i].rs = j;
                if(suf[i][j]==er[i].count/2 and er[i].count!=0){
                    er[i].re = j;
                    break;
                }
            }
        }
        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;

        int max_len = 1;
        fo(i,200){

            int start = er[i].le;
            int end = er[i].re;
            int curr_count = er[i].count;
            while (start>=0 and end<=n-1)
            {

                int count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                int mx_count = 0;
                for(int c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                //cout<<i+1<<" "<<start<<" "<<end<<" "<<mx_count<<endl;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    int count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        int pre[200][n];
        fo(i,200) pre[i][0] = 0;
        pre[a[0]-1][0] = 1;
        for(i=1;i<n;i++){
            fo(j,200){
                if(a[i]==j+1)
                    pre[j][i] = pre[j][i-1]+1;
                else
                    pre[j][i] = pre[j][i-1];
            }
        }
        /*fo(i,200){
            fo(j,n) cout<<pre[i][j]<<" ";
            cout<<endl;
        }*/
        //calc suffixes
        int suf[200][n];
        fo(i,200) suf[i][n-1] = 0;
        suf[a[n-1]-1][n-1] = 1;
        //cout<<endl;
        for(i=n-2;i>=0;i--){
            for(j=0;j<200;j++){
                suf[j][i] = suf[j][i+1];
                if(a[i]==j+1)
                    suf[j][i] = suf[j][i]+1;
            }
        }

        ends_range er[200];

        fo(i,200){
            er[i].count = (suf[i][0]/2)*2;
            fo(j,n){
                if(pre[i][j]==1) er[i].ls = j;
                if(pre[i][j]== er[i].count/2){
                    er[i].le = j;
                    break;
                }
            }
        }
        fo(i,200){
            for(j=n-1;j>=0;j--){
                if(suf[i][j]==1) er[i].rs = j;
                if(suf[i][j]==er[i].count/2 and er[i].count!=0){
                    er[i].re = j;
                    break;
                }
            }
        }
        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;

        int max_len = 1;
        fo(i,200){

            int start = er[i].le;
            int end = er[i].re;
            int curr_count = er[i].count;
            while (start>=0 and end<=n-1)
            {

                int count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                int mx_count = 0;
                for(int c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                //cout<<i+1<<" "<<start<<" "<<end<<" "<<mx_count<<endl;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        ll count[200] = {0};
        for(i=0;i<n;i++){
            count[a[i]-1]+=1;
        }
        bool broke = false;
        fo(i,200){
            if(count[i]==n){
                cout<<n<<endl;
                broke = true;
                break;
            }
        }
        if(broke) continue;
        ends_range er[200];

        fo(i,200){
            er[i].count = (count[i]/2)*2;
            ll cur_count = 0;
            fo(j,n){
                if(a[j]==i+1){
                    cur_count++;
                    if(cur_count==1) er[i].ls = j;
                    if(cur_count==count[i]/2) er[i].le = j;
                    if(cur_count==ceil(count[i]/2.0)+1) er[i].re = j;
                    if(cur_count==count[i]){
                        er[i].rs = j;
                        break;
                    }
                }
            }
        }

        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
        ll max_len = 1;
        fo(i,200){
            ll start = er[i].le;
            ll end = er[i].re;
            ll curr_count = er[i].count;
            while (start>=0 and end<=n-1 )
            {

                ll count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                ll mx_count = 0;
                for(ll c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                if((start+1+n-end)<=curr_count) break;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        ll count[200] = {0};
        for(i=0;i<n;i++){
            count[a[i]-1]+=1;
        }
        ends_range er[200];

        fo(i,200){
            er[i].count = (count[i]/2)*2;
            ll cur_count = 0;
            fo(j,n){
                if(a[j]==i+1){
                    cur_count++;
                    if(cur_count==1) er[i].ls = j;
                    if(cur_count==count[i]/2) er[i].le = j;
                    if(cur_count==ceil(count[i]/2.0)+1) er[i].re = j;
                    if(cur_count==count[i]){
                        er[i].rs = j;
                        break;
                    }
                }
            }
        }
        /*fo(i,200){
            for(j=n-1;j>0;j--){
                if(pre[i][j-1]==pre[i][n-1]-1) er[i].rs = j;
                if(pre[i][j-1]==ceil(pre[i][n-1]/2.0) and er[i].count!=0){
                    er[i].re = j;
                    break;
                }
            }
        }*/
        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
        ll max_len = 1;
        fo(i,200){
            ll start = er[i].le;
            ll end = er[i].re;
            ll curr_count = er[i].count;
            while (start>=0 and end<=n-1)
            {

                ll count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                ll mx_count = 0;
                for(ll c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>

#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long l;
typedef vector<int> vint;

struct ends_range{
    ll count=0,ls=0,le=0,rs=0,re=0;
};

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        ll n,i,j;
        cin>>n;
        int a[n];
        fo(i,n) cin>>a[i];

        //calc prefixes
        ll count[200] = {0};
        for(i=0;i<n;i++){
            count[a[i]-1]+=1;
        }
        ends_range er[200];

        fo(i,200){
            er[i].count = (count[i]/2)*2;
            ll cur_count = 0;
            fo(j,n){
                if(a[j]==i+1){
                    cur_count++;
                    if(cur_count==1) er[i].ls = j;
                    if(cur_count==count[i]/2) er[i].le = j;
                    if(cur_count==count[i]/2+1) er[i].re = j;
                    if(cur_count==count[i]){
                        er[i].rs = j;
                        break;
                    }
                }
            }
        }
        /*fo(i,200){
            for(j=n-1;j>0;j--){
                if(pre[i][j-1]==pre[i][n-1]-1) er[i].rs = j;
                if(pre[i][j-1]==ceil(pre[i][n-1]/2.0) and er[i].count!=0){
                    er[i].re = j;
                    break;
                }
            }
        }*/
        //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
        ll max_len = 1;
        fo(i,200){
            ll start = er[i].le;
            ll end = er[i].re;
            ll curr_count = er[i].count;
            while (start>=0 and end<=n-1)
            {

                ll count[200] = {0};
                for(j=start+1;j<end;j++){
                    count[a[j]-1] +=1;
                }
                ll mx_count = 0;
                for(ll c: count) if(c>mx_count) mx_count=c;
                if(max_len<(mx_count+curr_count)) max_len = mx_count+curr_count;
                curr_count -=2;
                start--;
                end ++;
                while(a[start]!=i+1 and start>=0) start--;
                while(a[end]!=i+1 and end<=n-1) end++;

            }
        }
        cout<<max_len<<endl;

    }
}