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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

#define ll int

#ifdef sarthak
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#else
#define trace(...)
#endif

#ifndef sarthak
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fort(i,v) for(auto i:v)
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) rep(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) rep(i,sizeof(ar)/sizeof(ar[0])) rep(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%d %d",&x,&y)
#define slld2(x,y) scanf("%lld %lld",&x,&y)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pd2(x,y) printf("%d %d\n",x,y)
#define plld2(x,y) printf("%lld %lld\n",x,y)
#define all(ar) ar.begin(), ar.end()
#define endl '\n'
#define sz(x) (int)x.size()
#define len(x) (int)x.length()

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

const ll N = 200000;
const ll K = 200;

ll p[N+1][K+1];
ll a[N+1];
vector<ll> v[K+1];

void allclear(ll n)
{
    fr(i,0,n)
    {
        fr(j,1,K)
        {
            p[i][j] = 0;
        }
    }
    fr(i,1,K)
    {
        v[i].clear();
    }
}

ll f(ll l, ll r)
{
    if(l>r)
        return 0;
    ll x1 = 0;
    fr(i,1,K)
    {
        x1 = max(x1,p[r][i]-p[l-1][i]);
    }

    return x1;
}

void solve()
{
    ll n;
    cin >> n;

    fr(i,1,n)
    {
        cin >> a[i];
        v[a[i]].pb(i);
    }

    fr(i,1,n)
    {
        fr(j,1,K)
        {
            p[i][j] = p[i-1][j];
        }
        p[i][a[i]]++;
    }

    ll ans = 0;

    fr(i,1,K)
    {
        ll nn = v[i].size();
        ll ans2 = nn;

        rep(j,nn/2)
        {
            ll l = v[i][j]+1;
            ll r = v[i][nn-j-1]-1;
            ll xx = f(l,r);
            ans2 = max(ans2,2*(j+1)+xx);
        }

        ans = max(ans,ans2);
    }

    cout << ans << endl;
    allclear(n);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout << setprecision(10);
    #ifdef sarthak
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    cin >> t;

    while(t--)
    {
        solve();
    }

    #ifdef sarthak
    cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    #endif
}


#include <bits/stdc++.h>
#include <functional> // for less
#include <iostream>
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(ar) ar.begin(), ar.end()
#define mp make_pair
#define sot(bello) bello.begin(), bello.end()
#define bitc __builtin_popcountl
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define fill(ar, val) rep(i, sizeof(ar) / sizeof(ll)) ar[i] = val
#define fill0(ar) fill((ar), 0)
#define foreach(it, ar) for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF
#define MOD 1000000007
#define MOD1 998244353
#define print(x) {  \
             cout<<x<<endl; \
             cerr<<endl; \
             return;    \
}
#define debug(x) cerr << #x << ": " << x << endl
#define arr1d(a, n)                  \
    cout << #a << " : ";             \
    fr(_, 1, n) cout << a[_] << ' '; \
    cout << endl;
#define arr1d0(a, n)               \
    cout << #a << " : ";           \
    rep(_, n) cout << a[_] << ' '; \
    cout << endl;
#define arr2d(a, n, m)                        \
    cout << #a << " :" << endl;               \
    fr(_, 1, n)                               \
    {                                         \
        fr(__, 1, m) cout << a[_][__] << ' '; \
        cout << endl;                         \
    }
#define arr2d0(a, n, m)                     \
    cout << #a << " :" << endl;             \
    rep(_, n)                               \
    {                                       \
        rep(__, m) cout << a[_][__] << ' '; \
        cout << endl;                       \
    }
#define clr(a) memset(a, 0, sizeof(a))
#define dbug(x) cerr << #x << ": " << x << " "
auto clk = clock();
#define PI 3.1415926535897932385
#define fi first
#define se second
#define arr1d(a, n)                  \
    cout << #a << " : ";             \
    fr(_, 1, n) cout << a[_] << ' '; \
    cout << endl;
#define arr1d0(a, n)               \
    cout << #a << " : ";           \
    rep(_, n) cout << a[_] << ' '; \
    cout << endl;
#define arr2d(a, n, m)                        \
    cout << #a << " :" << endl;               \
    fr(_, 1, n)                               \
    {                                         \
        fr(__, 1, m) cout << a[_][__] << ' '; \
        cout << endl;                         \
    }
#define arr2d0(a, n, m)                     \
    cout << #a << " :" << endl;             \
    rep(_, n)                               \
    {                                       \
        rep(__, m) cout << a[_][__] << ' '; \
        cout << endl;                       \
    }

#define INF 1000000000000000000
const ld PI2 = acos(-1) / 2.0l;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
const int dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
/* This Template is authored by Ankit Anvesh */

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// gcd for negatives too
/* ll gcd(ll a, ll b) {
 if (a == 0) return b;
 if (b == 0) return a;
 if (b < 0) return gcd(a, -1 * b);
 if (a < 0) return gcd(-1 * a, b);
 if (a > b) return gcd(b, a);
 return gcd(b%a, a);
}
 */

//gcd

const ll MAXN=100010;

ll Gcd(ll a, ll b)
{
    if (a % b == 0)
        return b;
    return Gcd(b, a % b);
}
//max
ll Max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}
//min
ll Min(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

void printvector(std::vector<ll> v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        cout << v[i] << " ";
    }
    cout << "" << endl;
}
void printarray(ll a[], ll n)
{
    for (ll i = 0; i < n; ++i)
    {
        cout << a[i] << " ";
    }
    cout << "" << endl;
}

ll findlcm(vector<ll> arr, ll n)
{
    // Initialize result
    ll ans = arr[0];

    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
               (Gcd(arr[i], ans)));

    return ans;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll lowerbound(ll k, vector<ll> v)
{
    //lowerbound to be used when first index such that
    // ar[index]>=k is needed

    ll l = 0;
    ll size = v.size();
    ll r = size - 1;
    ll mid;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (v[mid] < k)
            l = mid + 1;
        else
        {
            r = mid - 1;
        }
    }
    return l;
}

ll upperbound(ll k, vector<ll> v)
{
    //lowerbound to be used when first index such that
    // ar[index]>k is needed
    ll l = 0;
    ll size = v.size();
    ll r = size - 1;
    ll mid;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (v[mid] > k)
            r = mid - 1;
        else
        {
            l = mid + 1;
        }
    }
    return l;
}

ll spf[MAXN];

void sieve()
{
    spf[1] = 1;
    for (int i = 2; i < MAXN; i++)
        spf[i] = i;
    for (int i = 4; i < MAXN; i += 2)
        spf[i] = 2;

    for (int i = 3; i * i < MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j = i * i; j < MAXN; j += i)
                if (spf[j] == j)
                    spf[j] = i;
        }
    }
}

//Segment Tree Implementation

//const ll N = 100000;

ll n, m;

// BIT tree
/*
start indexing from 1
ll BIT[100010];
void update(ll x,ll val){

  for (; x <=n ; x +=(x&(-x)) )
     BIT[x]+=val;

}
ll query(ll x){
  ll sum=0;
  for(;x>0;x -= (x&(-x)) )
    sum+=BIT[x];
  return sum;

}*/

//Dijkstra's Algorithm
// if x->y (weight=w) then v[x].push_back(mp(y,w));

vector<ll> shortPath(vector<pair<ll, ll>> v[], ll src, ll V = 0)
{
    set<pair<ll, ll>> setds;

    ll sizee = V;
    ll IN = INF;
    vector<ll> dist(sizee, IN);
    vector<bool> vis(sizee, false);
    setds.insert(make_pair(0, src));
    dist[src] = 0;

    while (!setds.empty())
    {
        pair<ll, ll> tmp = *(setds.begin());
        setds.erase(setds.begin());

        ll u = tmp.second;
        if (vis[u])
            continue;
        vis[u] = true;
        vector<pair<ll, ll>>::iterator i;
        for (auto i = v[u].begin(); i != v[u].end(); ++i)
        {
            ll v = (*i).first;
            ll weight = (*i).second;
            if (dist[v] > dist[u] + weight)
            {
                if (dist[v] != INF)
                    setds.erase(setds.find(make_pair(dist[v], v)));

                dist[v] = dist[u] + weight;
                setds.insert(make_pair(dist[v], v));
            }
        }
    }
    return dist;
}

ll root(ll a[], ll r)
{
    if (a[r] == r)
    {
        return r;
    }
    else
    {
        ll x = root(a, a[r]);
        a[r] = x;
        return x;
    }
}

void unio(ll a[], ll size[], ll x, ll y)
{
    x = root(a, x);
    y = root(a, y);
    if (x == y)
    {
        return;
    }
    if (size[x] >= size[y])
    {
        a[y] = x;
        size[x] += size[y];
    }
    else
    {
        a[x] = y;
        size[y] += size[x];
    }
}

// Sieve Implementation
/*
for (ll i=2;i<=100005;i++)
        if (p[i]==0)
        for (ll j=2*i;j<=100005;j+=i) p[j]=1; */

// Dfs search

//do not use n , m , N , C

// Using iterators in C++
//set<ll>:: iterator it;
// string to integer stuuu()
// string to long long stoll()
// string to float stof
// string.substr(position,length);
// integer to string to_string();
// intialize 2d vector vector<vector<ll>> dp(105,vector<ll>(105));
// for taking ceil use (num+den-1)/den
// for declaring min heap use this complicated shit priority_queue<ll,vector<ll>,greater<ll>> q;

void neuer(ll txt)
{
   cin>>n;
   //vector<vector<ll>> fa(205,vector<ll>(n));

   vector<ll> as[205];
   //vector<ll> sa[205];
   vector<ll> ar(n);

   rep(i,n){
       cin>>ar[i];
       ll vl;
       vl=ar[i];
       if(i==0){
           //fa[vl][i]++;
       }
       else
       {
           /* fa[vl][i]++;
           rep(j,203){
               fa[j][i]+=fa[j][i-1];
           } */
       }
       as[vl].push_back(i);
   }
  /*  repr(i,n){
      // cin>>ar[i];
       /* if(i==n-1){
           af[ar[i]][i]++;
       }
       else
       {
           rep(j,203){
               af[j][i]+=af[j][i+1];
           }
       } */
      // sa[ar[i]].push_back(i);
   //} */
   //debug(fa[1][0]);
   ll mx=0;

       rep(j,203){
           ll sz=as[j].size();
           mx=max(mx,sz);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c;
       //c=fa[ar[i]][i];
       //c--;
       //dbug(ar[i]); debug(c);
       ll in;
       l=0;
       r=as[ar[i]].size()-1;
       ll midd;
       while(l<=r){
           midd=(l+r)/2;
           if(as[ar[i]][midd]>i){
               r=midd-1;
           }
           else if(as[ar[i]][midd]<i){
               l=midd+1;
           }
           else
           {
               c=midd;
               break;
           }
       }

       l=as[ar[i]][c]+1;
       ll oi=as[ar[i]].size();
       r=as[ar[i]][oi-c-1]-1;
       //debug(fa[1][0]);
     //  dbug(l); debug(r);
       if(l>r or l>=n or r<0){
           l--;
           r++;
           continue;
       }

       ll ma=0;
       rep(j,203){
           ll cc;
           //cc=fa[j][r]-fa[j][l-1];
           ll la=0,lr=(ll)as[j].size();
           lr--;
           ll mi;
           ll k1=lr+1,k2=0;
           while(la<=lr){
               mi=(la+lr)/2;
               if(/* as[j][mi]>=l and */ as[j][mi]<=r){
                 //k1=min(k1,mi);
                 k2=max(k2,mi);
                 la=mi+1;
               }
               else
               {
                   lr=mi-1;
               }

           }
           la=0,lr=(ll)as[j].size();
           lr--;
           while(la<=lr){
               mi=(la+lr)/2;
               if(/* as[j][mi]>=l and */ as[j][mi]>=l){
                 //k1=min(k1,mi);
                 k1=min(k1,mi);
                 lr=mi-1;
               }
               else
               {
                   la=mi+1;
               }
           }
           cc=k2-k1+1;
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   print(mx);

   return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x68 = 1;
    cin >> x68;
   for (ll vi = 1; vi <= x68; vi++)
    {
        neuer(vi);
    }

    return 0;
}


 #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>  ordered_set;
using namespace std;

#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define fillinf(ar, n) fr(i,0,(n)) ar[i] = INF
#define debug(x) cout<<#x<<": "<<x<<endl
#define arr1d(a,n) cout << #a << " : "; fr(_,1,n) cout << a[_] << ' '; cout << endl;
#define arr1d0(a,n) cout << #a << " : "; rep(_,n) cout << a[_] << ' '; cout << endl;
#define arr2d(a,n,m) cout << #a << " :" << endl; fr(_,1,n) {fr(__,1,m) cout << a[_][__] << ' '; cout << endl;}
#define arr2d0(a,n,m) cout << #a << " :" << endl; rep(_,n) {rep(__,m) cout << a[_][__] << ' '; cout << endl;}
/*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */
/*IIT Roorkee = <3 */
#define ull unsigned long long
#define ld double
#define ui unsigned int
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define y0 yyyyyy0
auto clk=clock();
#define y1 yyyyyy1

#define BIT(n) (1<<(n))
#define SQR(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define LSOne(S) (S) & (-S)
inline bool EQ(double a, double b) {return fabs(a - b) < 1e-9;}

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;

template<typename T>inline T gcd(T a, T b){if (b == 0)return a;else return gcd(b, a % b);}
template<typename T>inline T lcm(T a, T b){return (a * b) / gcd(a, b);}
template<typename T> string toStr(T x) {stringstream st; st << x; string s; st >> s; return s;}
template<class T>
void splitStr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

inline int two(int n) {return 1 << n;}
inline int isOnBit(int n, int b) {return (n >> b) & 1;}
inline void onBit(int & n, int b) {n |= two(b);}
inline void offBit(int & n, int b) {n &= ~two(b);}
inline int lastBit(int n) {return n & (-n);}
inline int cntBit(int n) {int res = 0; while(n && ++res) n -= n &(-n); return res;}

const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};

#define INP "test.inp"
#define OUT "test.out"

#define PI 3.1415926535897932385
#define INF 1000000000000000000
#define EPS 1e-7
#define MAXN 100000
#define MOD 998244353ll
#define dec decr
//END OF COMPETITVE PROGRAMMING TEMPLATE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll modexp(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y %2==1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<fixed;
    cout<<setprecision(9);
    ll t;
    cin>>t;
    while(t--)
   {
    ll n;
     cin>>n;
   //vector<vector<ll>> fa(205,vector<ll>(n));

   vector<ll> as[205];
   //vector<ll> sa[205];
   vector<ll> ar(n);
   vector<ll> sd(n);

   rep(i,n){
       cin>>ar[i];
       ll vl;
       vl=ar[i];
       if(i==0){
           //fa[vl][i]++;
       }
       else
       {
           /* fa[vl][i]++;
           rep(j,203){
               fa[j][i]+=fa[j][i-1];
           } */
       }
       as[vl].push_back(i);
       sd[i]=as[vl].size();
   }
  /*  repr(i,n){
      // cin>>ar[i];
       /* if(i==n-1){
           af[ar[i]][i]++;
       }
       else
       {
           rep(j,203){
               af[j][i]+=af[j][i+1];
           }
       } */
      // sa[ar[i]].push_back(i);
   //} */
   //debug(fa[1][0]);
   ll mx=0;

       rep(j,203){
           ll sz=as[j].size();
           mx=max(mx,sz);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c;
       //c=fa[ar[i]][i];
       //c--;
       //dbug(ar[i]); debug(c);
       ll in;
       l=0;
       r=as[ar[i]].size()-1;
       ll midd;
       /* while(l<=r){
           midd=(l+r)/2;
           if(as[ar[i]][midd]>i){
               r=midd-1;
           }
           else if(as[ar[i]][midd]<i){
               l=midd+1;
           }
           else
           {
               c=midd;
               break;
           }
       } */
       c=sd[i]-1;

       l=as[ar[i]][c]+1;
       ll oi=as[ar[i]].size();
       r=as[ar[i]][oi-c-1]-1;
       //debug(fa[1][0]);
     //  dbug(l); debug(r);
       if(l>r or l>=n or r<0){
           l--;
           r++;
           continue;
       }

       ll ma=0;
       rep(j,203){
           ll cc;
           //cc=fa[j][r]-fa[j][l-1];
           ll la=0,lr=(ll)as[j].size();
           lr--;
           ll mi;
           ll k1=lr+1,k2=0;
           while(la<=lr){
               mi=(la+lr)/2;
               if(/* as[j][mi]>=l and */ as[j][mi]<=r){
                 //k1=min(k1,mi);
                 k2=max(k2,mi);
                 la=mi+1;
               }
               else
               {
                   lr=mi-1;
               }

           }
           la=0,lr=(ll)as[j].size();
           lr--;
           while(la<=lr){
               mi=(la+lr)/2;
               if(/* as[j][mi]>=l and */ as[j][mi]>=l){
                 //k1=min(k1,mi);
                 k1=min(k1,mi);
                 lr=mi-1;
               }
               else
               {
                   la=mi+1;
               }
           }
           cc=k2-k1+1;
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;

   }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,m,q;
    t()
    {
        cin>>n;
        vi a(n);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,0,n)
        {
            cin>>a[i];
            m[a[i]]++;
        }
        vi k;
        int y=0;
        for(auto i:m)
        {
            k.pb(i.F);
            if(y<i.S)
                y=i.S;
        }
        int sz=k.size();
        m.clear();

        rep(i,0,sz)
        {
            x=k[i];
            l=0,r=n-1;
            int cnts=0,cnte=0,pos_start=0,pos_end=n-1,cnt=0;
            while(l<=r)
            {
                //trace(a[l],a[r],pos_start,pos_end);
                if(a[l]==x )
                {
                    pos_start=l;
                    cnts++;
                }
                if(a[r]==x)
                {
                    pos_end=r;
                    cnte++;
                }
                l++;
                r--;
            }
           // trace(cnts,cnte,x);

            if(cnts==cnte)
            {
                cnt=cnte;
            }
            else
            {
                cnt=min(cnts,cnte);
                if(cnt==cnts)
                {
                    pos_end+=cnte-cnts;
                }
                else
                {
                    pos_start-=cnts-cnte;
                }
            }

            rep(j,pos_start+1,pos_end)
            {
                m[a[j]]++;
            }
            int maxi=0;
            for(auto j:m)
            {
                if(maxi<j.S)
                {
                    maxi=j.S;
                }
            }
            m.clear();
            ans=max(ans,(cnt*2+maxi));

        }
        ans=max(ans,y);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353

#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const int N=2e5+5;
int32_t pre[N][201];
vi s[201];
int32_t a[N];
int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k;
    t()
    {
        cin>>n;
        rep(i,1,201)
        {
            s[i].clear();
        }
        rep(i,1,n+1)
        {
            cin>>a[i];
            s[a[i]].pb(i);
            rep(j,1,201)
            {
                pre[i][j]=pre[i-1][j];
            }
            pre[i][a[i]]++;
        }

        int ans=0,ind1,ind2;
        rep(i,1,201)
        {
            int sz=s[i].size();
            ans=max(ans,sz);
            rep(j,0,sz/2)
            {
                ind1=s[i][j];
                ind2=s[i][sz-1-j];
                int maxi=0;
                rep(k,1,201)
                {
                    if(i==k)continue;
                    maxi=max(maxi,pre[ind2][k]-pre[ind1][k]);
                }
                ans=max(ans,(j+1)*2+maxi);
            }
        }

        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,m,q;
    t()
    {
        cin>>n;
        vi a(n);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,0,n)
        {
            cin>>a[i];
            m[a[i]]++;
        }
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        vi k;
        int y=0;
        for(auto i:m)
        {
            k.pb(i.F);
            if(y<i.S)
                y=i.S;
        }
        int sz=k.size();
        m.clear();
       vi ind;
        rep(i,0,sz)
        {
            x=k[i];
            l=0,r=n-1;
            int pos_start=0,pos_end=n-1,cnt=0;
           rep(q,0,n)
            {
                //trace(a[l],a[r],x);
                if(a[q]==x )
                {
                    ind.pb(q);
                }

            }
            //trace(ind.size(),x);
            if(ind.size()==1)
                {
                    ind.clear();
                    continue;
                }
            cnt=ind.size();
            if(cnt&1)
            {
                pos_start=ind[cnt/2-1];
                pos_end=ind[cnt/2+1];
            }
            else
            {
                pos_start=ind[cnt/2-1];
                pos_end=ind[cnt/2];
            }
            //trace(pos_start,pos_end,x);
            ind.clear();
            rep(j,pos_start+1,pos_end)
            {
                m[a[j]]++;
            }
            int maxi=0;
            for(auto j:m)
            {
                if(maxi<j.S)
                {
                    maxi=j.S;
                }
            }
            m.clear();
            //trace(cnt,maxi);
            if(cnt&1)cnt--;
            ans=max(ans,(cnt+maxi));

        }
        //trace(ans,y);
        ans=max(ans,y);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,m,q;
    t()
    {
        cin>>n;
        vi a(n);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,0,n)
        {
            cin>>a[i];
            m[a[i]]++;
        }
        vi k;
        for(auto i:m)
        {
            k.pb(i.F);
        }
        int sz=k.size();
        m.clear();

        rep(i,0,sz)
        {
            x=k[i];
            l=0,r=n-1;
            int cnts=0,cnte=0,pos_start=-1,pos_end=-1,cnt=0;
            while(l<r)
            {
                //trace(a[l],a[r],pos_start,pos_end);
                if(a[l]==x )
                {
                    pos_start=l;
                    cnts++;
                }
                if(a[r]==x)
                {
                    pos_end=r;
                    cnte++;
                }
                l++;
                r--;
            }
           // trace(cnts,cnte,x);
            if(cnts==cnte)
            {
                cnt=cnte;
            }
            else
            {
                cnt=min(cnts,cnte);
                if(cnt==cnts)
                {
                    pos_end+=cnte-cnts;
                }
                else
                {
                    pos_start-=cnts-cnte;
                }
            }

            rep(j,pos_start+1,pos_end)
            {
                m[a[j]]++;
            }
            int maxi=0;
            for(auto j:m)
            {
                if(maxi<j.S)
                {
                    maxi=j.S;
                }
            }
            m.clear();
            ans=max(ans,(cnt*2+maxi));

        }
        ans=max(ans,1ll);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,m,q;
    t()
    {
        cin>>n;
        vi a(n);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,0,n)
        {
            cin>>a[i];
            m[a[i]]++;
        }
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        vi k;
        int y=0;
        for(auto i:m)
        {
            k.pb(i.F);
            if(y<i.S)
                y=i.S;
        }
        int sz=k.size();
        m.clear();

        rep(i,0,sz)
        {
            x=k[i];
            l=0,r=n-1;
            int cnts=0,cnte=0,pos_start=0,pos_end=n-1,cnt=0;
            while(l<r)
            {
                //trace(a[l],a[r],pos_start,pos_end);
                if(a[l]==x )
                {
                    pos_start=l;
                    cnts++;
                }
                if(a[r]==x)
                {
                    pos_end=r;
                    cnte++;
                }
                l++;
                r--;
            }
           // trace(cnts,cnte,x);

            if(cnts==cnte)
            {
                cnt=cnte;
            }
            else
            {
                cnt=min(cnts,cnte);
                if(cnt==cnts)
                {
                    pos_end+=cnte-cnts;
                }
                else
                {
                    pos_start-=cnts-cnte;
                }
            }
            if(cnt==0)continue;

            rep(j,pos_start+1,pos_end)
            {
                m[a[j]]++;
            }
            int maxi=0;
            for(auto j:m)
            {
                if(maxi<j.S)
                {
                    maxi=j.S;
                }
            }
            m.clear();
           // trace(cnt,maxi);

            ans=max(ans,(cnt*2+maxi));

        }
        //trace(ans,y);
        ans=max(ans,y);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
const int N=2e5+5;
int pre[N][201];
vi s[201];
int a[N];
int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k;
    t()
    {
        cin>>n;
        rep(i,1,201)
        {
            s[i].clear();
        }
        rep(i,1,n+1)
        {
            cin>>a[i];
            s[a[i]].pb(i);
            rep(j,1,201)
            {
                pre[i][j]=pre[i-1][j];
            }
            pre[i][a[i]]++;
        }

        int ans=0,ind1,ind2;
        rep(i,1,201)
        {
            int sz=s[i].size();
            ans=max(ans,sz);
            rep(j,0,sz/2)
            {
                ind1=s[i][j];
                ind2=s[i][sz-1-j];
                int maxi=0;
                rep(k,1,201)
                {
                    if(i==k)continue;
                    maxi=max(maxi,pre[ind2][k]-pre[ind1][k]);
                }
                ans=max(ans,(j+1)*2+maxi);
            }
        }

        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int pre[2000001][201];
int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,q,p;

    t()
    {
        cin>>n;
        vi a(n+1);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,1,n+1)
        {
            cin>>a[i];
            m[a[i]]++;
            rep(j,1,201)
            {
                pre[i][j]=pre[i-1][j];
            }
            pre[i][a[i]]++;

        }
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        vi k;
        int y=0;
        for(auto i:m)
        {
            k.pb(i.F);
            if(y<i.S)
                y=i.S;
        }
        int sz=k.size();
        m.clear();
       vi ind;
        rep(i,0,sz)
        {
            x=k[i];

            int pos_start=0,pos_end=n-1,cnt=0;
           rep(q,1,n+1)
            {

                if(a[q]==x )
                {
                    ind.pb(q);
                }

            }

            if(ind.size()==1)
                {
                    ind.clear();
                    continue;
                }
            cnt=ind.size();

            rep(p,0,cnt/2)
            {
                pos_start=ind[p];
                pos_end=ind[cnt-1-p];
                int maxi=0;
                rep(j,1,201)
                {
                    if(j==k[i])continue;
                    maxi=max(maxi,pre[pos_end][j]-pre[pos_start][j]);
                }
                //trace(maxi,pos_start,pos_end,(p+1)*2);
                ans=max(ans,((p+1)*2+maxi));
            }
            ind.clear();

        }

        ans=max(ans,y);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,q,p;
    t()
    {
        cin>>n;
        vi a(n);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,0,n)
        {
            cin>>a[i];
            m[a[i]]++;
        }
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        vi k;
        int y=0;
        for(auto i:m)
        {
            k.pb(i.F);
            if(y<i.S)
                y=i.S;
        }
        int sz=k.size();
        m.clear();
       vi ind;
        rep(i,0,sz)
        {
            x=k[i];
            l=0,r=n-1;
            int pos_start=0,pos_end=n-1,cnt=0;
           rep(q,0,n)
            {
                //trace(a[l],a[r],x);
                if(a[q]==x )
                {
                    ind.pb(q);
                }

            }
            //trace(ind.size(),x);
            if(ind.size()==1)
                {
                    ind.clear();
                    continue;
                }
            cnt=ind.size();

            //trace(pos_start,pos_end,x);
            rep(p,0,cnt/2)
            {
                rep(j,ind[p]+1,ind[cnt-1-p])
                {
                    m[a[j]]++;
                }
                int maxi=0;
                for(auto j:m)
                {
                    if(maxi<j.S)
                    {
                        maxi=j.S;
                    }
                }
                m.clear();
                //trace((p+1)*2,maxi);
                ans=max(ans,((p+1)*2+maxi));
            }
            ind.clear();

        }
        //trace(ans,y);
        ans=max(ans,y);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

int pre[200001][201];
int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k,q,p;

    t()
    {
        cin>>n;
        vi a(n+1);
        int l,r;
        int ans=0,x;
        mii m;
        rep(i,1,n+1)
        {
            cin>>a[i];
            m[a[i]]++;
            rep(j,1,201)
            {
                pre[i][j]=pre[i-1][j];
            }
            pre[i][a[i]]++;

        }
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        vi k;
        int y=0;
        for(auto i:m)
        {
            k.pb(i.F);
            if(y<i.S)
                y=i.S;
        }
        int sz=k.size();
        m.clear();
       vi ind;
        rep(i,0,sz)
        {
            x=k[i];

            int pos_start=0,pos_end=n-1,cnt=0;
           rep(q,1,n+1)
            {

                if(a[q]==x )
                {
                    ind.pb(q);
                }

            }

            if(ind.size()==1)
                {
                    ind.clear();
                    continue;
                }
            cnt=ind.size();

            rep(p,0,cnt/2)
            {
                pos_start=ind[p];
                pos_end=ind[cnt-1-p];
                int maxi=0;
                rep(j,1,201)
                {
                    if(j==k[i])continue;
                    maxi=max(maxi,pre[pos_end][j]-pre[pos_start][j]);
                }
                //trace(maxi,pos_start,pos_end,(p+1)*2);
                ans=max(ans,((p+1)*2+maxi));
            }
            ind.clear();

        }

        ans=max(ans,y);
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define     mod             1e9+7
#define     MOD             998244353
#define     int             long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     pb              emplace_back
#define     pf              emplace_front
#define     all(p)          p.begin(), p.end()
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
#define     t()             int test;cin>>test;while(test--)
#define     setbits(x)      __builtin_popcountll(x)
#define     si              set<int>
#define     mii             map<int,int>
#define     vi              vector<int>
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vi, greater<int> >
#define     vii             vector<ii>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
const int N=2e5;
int pre[N+2][201];
vi s[201];
vi a(N+2);
int32_t main()

{
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif
    IOS;
    int i,j,n,k;
    t()
    {
        cin>>n;
        rep(i,1,201)
        {
            s[i].clear();
        }
        rep(i,1,n+1)
        {
            cin>>a[i];
            s[a[i]].pb(i);
            rep(j,1,201)
            {
                pre[i][j]=pre[i-1][j];
            }
            pre[i][a[i]]++;
        }

        int ans=0,ind1,ind2;
        rep(i,1,201)
        {
            int sz=s[i].size();
            ans=max(ans,sz);
            rep(j,0,sz/2)
            {
                ind1=s[i][j];
                ind2=s[i][sz-1-j];
                int maxi=0;
                rep(k,1,201)
                {
                    if(i==k)continue;
                    maxi=max(maxi,pre[ind2][k]-pre[ind1][k]);
                }
                ans=max(ans,(j+1)*2+maxi);
            }
        }

        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l <= r)
        {
            if (l == r)
            {
                c1++;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            count[i] = INT_MIN;
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
        if (min(c1, c2) * 2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;
        for (int j = 0; j < n; j++)
            if (a[j] == i)
            {
                l = j;
                break;
            }

        for (int j = n - 1; j >= 0; j--)
            if (a[j] == i)
            {
                r = j;
                break;
            }
        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (a[j] == i)
                {
                    if (count[a[j]] + c1 + c2 >= len)
                        return 1;
                }
                else if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
        if (min(c1, c2) * 2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;
        for (int j = 0; j < n; j++)
            if (a[j] == i)
            {
                l = j;
                break;
            }

        for (int j = n - 1; j >= 0; j--)
            if (a[j] == i)
            {
                r = j;
                break;
            }
        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (a[j] == i)
                {
                    if (count[a[j]] + c1 + c2 == len)
                        return 1;
                }
                else if (count[a[j]] + (min(c1, c2) * 2) == len || min(c1, c2) * 2 == len)
                {
                    return 1;
                }
            }
        }
        if (c1 + c2 == len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

vector<vector<int>> v(201, vector<int>(200001, 0));

bool possible(int a[], int len, int n)
{
    // x and y can be zero
    // so how to find that is it possible to get pal of length len

    for (int j = 1; j <= 200; j++)
    {
        int count[201] = {0};
        count[j] = INT_MIN;
        if (v[j][n - 1] >= len)
            return 1;
        for (int i = 0; i < n; i++)
        {
            count[a[i]]++;
            if (a[i] == j)
            {
                memset(count, 0, sizeof(count));
            }
            else if (min(v[j][i], v[j][n - 1] - v[j][i]) * 2 + count[a[i]] >= len)
                return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];

        for (int i = 1; i <= 200; i++)
        {
            if (a[0] == i)
                v[i][0] = 1;
            else
                v[i][0] = 0;
            for (int j = 1; j < n; j++)
            {
                if (a[j] == i)
                    v[i][j] = v[i][j - 1] + 1;
                else
                    v[i][j] = v[i][j - 1];
            }
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l < r)
        {
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            count[i] = INT_MIN;
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
        if (min(c1, c2) * 2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l < r)
        {
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            count[i] = INT_MIN;
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 0, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;
        for (int j = 0; j < n; j++)
            if (a[j] == i)
            {
                l = j;
                break;
            }

        for (int j = n - 1; j >= 0; j--)
            if (a[j] == i)
            {
                r = j;
                break;
            }
        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len && min(c2, c1) > 0)
                {
                    return 1;
                }
            }
        }
        if (min(c1, c2) * 2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;
        for (int j = 0; j < n; j++)
            if (a[j] == i)
            {
                l = j;
                break;
            }

        for (int j = n - 1; j >= 0; j--)
            if (a[j] == i)
            {
                r = j;
                break;
            }
        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (a[j] == i)
                {
                    if (count[a[j]] + c1 + c2 >= len)
                        return 1;
                }
                else if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
        if (c1 + c2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

vector<vector<int>> v(201, vector<int>(200001, 0));

bool possible(int a[], int len, int n)
{
    // x and y can be zero
    // so how to find that is it possible to get pal of length len

    for (int j = 1; j <= 200; j++)
    {
        int count[201] = {0};
        count[j] = INT_MIN;
        if (v[j][n - 1] >= len)
            return 1;
        for (int i = 0; i < n; i++)
        {
            count[a[i]]++;
            if (a[i] == j)
            {
                memset(count, 0, sizeof(count));
            }
            else if (min(v[j][i], v[j][n - 1] - v[j][i]) * 2 + count[a[i]] >= len)
                return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];

        for (int i = 1; i <= 200; i++)
        {
            if (a[0] == i)
                v[i][0] = 1;
            else
                v[i][0] = 0;
            for (int j = 1; j < n; j++)
            {
                if (a[j] == i)
                    v[i][j] = v[i][j - 1] + 1;
                else
                    v[i][j] = v[i][j - 1];
            }
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l < r)
        {
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }
            if (c1 == c2)
            {
                int count[201] = {0};
                count[i] = INT_MIN;
                for (int j = l; j <= r; j++)
                {
                    count[a[j]]++;
                    if (count[a[j]] + c1 + c2 == len)
                    {
                        return 1;
                    }
                }
            }
        }
    }
    return 0;
}

int32_t main()
{
    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n <= 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 0, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;
        for (int j = 0; j < n; j++)
            if (a[j] == i)
            {
                l = j;
                break;
            }

        for (int j = n - 1; j >= 0; j--)
            if (a[j] == i)
            {
                r = j;
                break;
            }
        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
        if (min(c1, c2) * 2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    w(t)
    {
        int n;
        cin >> n;
        int a[n + 1];
        int count[201];
        memset(count, 0, sizeof(count));
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            count[a[i]]++;
        }
        int ans = 1;
        for (int start = 1; start <= 200; start++)
        {
            if (count[start] == 0)
                continue;
            int temp = count[start];
            int c[201] = {0};
            int c2 = 0;
            int l = 0, r = n - 1;

            while (l < r)
            {
                while (l < r && a[l] != start)
                {
                    c[a[l]]++;
                    l++;
                }
                while (l < r && a[r] != start)
                {
                    c[a[r]]++;
                    r--;
                }
                if (l >= r)
                    break;
                c2++;
                int maxm = 0;
                for (int i = 1; i <= 200; i++)
                {
                    if (i == start)
                        continue;
                    maxm = max(maxm, count[i] - c[i]);
                }
                temp = max(temp, maxm + c2 + c2);
                l++;
                r--;
            }
            ans = max(ans, temp);
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l < r)
        {
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }
            int count[201] = {0};
            count[i] = INT_MIN;
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
    }
    return 0;
}

int32_t main()
{
    _
        w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n <= 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 0, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define _ ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

bool possible(int a[], int len, int n)
{
    for (int i = 1; i <= 200; i++)
    {
        int l = 0, r = n - 1;
        int c1 = 0, c2 = 0;
        bool ok = 0;

        while (l <= r)
        {
            if (l == r && a[l] == i)
            {
                c1++;
                l++;
                r--;
                break;
            }
            if (a[l++] == i)
            {
                c1++;
            }

            if (a[r--] == i)
            {
                c2++;
            }

            int count[201] = {0};
            count[i] = INT_MIN;
            for (int j = l; j <= r; j++)
            {
                count[a[j]]++;
                if (count[a[j]] + (min(c1, c2) * 2) >= len)
                {
                    return 1;
                }
            }
        }
        if (min(c1, c2) * 2 >= len)
        {
            return 1;
        }
    }
    return 0;
}

int32_t main()
{

    w(t)
    {
        int n;
        cin >> n;

        int a[n + 1];

        for (int i = 0; i < n; i++)
            cin >> a[i];
        if (n == 1)
        {
            cout << 1 << "\n";
            continue;
        }
        if (n == 2)
        {
            if (a[0] == a[1])
            {
                cout << 2 << "\n";
            }
            else
            {
                cout << 1 << "\n";
            }
            continue;
        }
        if (n == 3)
        {
            if (a[0] == a[2])
            {
                cout << 3 << "\n";
            }
            else
            {
                if (a[0] == a[1] || a[1] == a[2])
                {
                    cout << 2 << "\n";
                }
                else
                {
                    cout << 1 << "\n";
                }
            }
            continue;
        }
        int l = 1, r = n;
        int ans = 0;

        while (l <= r)
        {
            int m = (l + r) / 2;

            if (possible(a, m, n))
            {
                l = m + 1;
                ans = max(ans, m);
            }
            else
            {
                r = m - 1;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int three_block_length(int start,int mid,int freq[][201],int a[],int n,vector<int> occ)
{
    if(start==mid)
        return freq[n-1][start];
    if(freq[n-1][start]==0)
    {
        return freq[n-1][mid];
    }
    if(freq[n-1][mid]==0)
    {
        return freq[n-1][start];
    }
    int maxLength=0;
    for(int i=0;i<occ.size()/2;i++)
    {
        maxLength=max(maxLength,2*(i+1)-freq[occ[i]][mid]+freq[occ[occ.size()-1-i]][mid]);
    }
    return maxLength;
}
void set_freq(int f[][201],int n,int a[],int &maxL)
{
    for(int i=1;i<=200;i++)
    {
        f[0][i]=a[0]==i?1:0;
        maxL=max(maxL,f[0][i]);
    }
    for(int i=1;i<=200;i++)
    {
        for(int j=1;j<n;j++)
        {
            f[j][i]=a[j]==i?f[j-1][i]+1:f[j-1][i];
            maxL=max(maxL,f[j][i]);
            //cout<<"setted\n";
        }
    }
}
int main()
{
    int t;
    cin>>t;
    int n;
    while(t--)
    {
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int freq[n][201];
        int maxLength=0;
        set_freq(freq,n,a,maxLength);
        vector< vector<int> > occ(201);
        for(int i=0;i<n;i++)
        {
            occ[a[i]].push_back(i);
            //maxLength=max(maxLength,occ[a[i]]);
        }
        for(int extreme_number=1;extreme_number<201;extreme_number++)
        {
            for(int mid_number=1;mid_number<201;mid_number++)
            {
                maxLength=max(maxLength,three_block_length(extreme_number,mid_number,freq,a,n,occ[extreme_number]));
            }

        }
        cout<<maxLength<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void next_low(int &low,int a[],int n,int &extreme_count,int &mid_count,int start,int mid)
{
    low++;
    while(low<n && a[low]!=start)
    {
        if(a[low]==start)
        {
            extreme_count++;
        }
        else if(a[low]==mid)
        {
            mid_count--;
        }
        low++;
    }
    if(a[low]==start)
    {
        extreme_count++;
    }
}
void next_high(int &high,int a[],int n,int &extreme_count,int &mid_count,int start,int mid)
{
    high--;
    while(high>-1 && a[high]!=start)
    {
        if(a[high]==start)
        {
            extreme_count++;
        }
        else if(a[high]==mid)
        {
            mid_count--;
        }
        high--;
    }
    if(a[high]==start)
    {
        extreme_count++;
    }
}
int three_block_length(int start,int mid,int freq[][201],int a[],int n,vector<int> occ)
{
    if(start==mid)
        return freq[n-1][start];
    if(freq[n-1][start]==0)
    {
        return freq[n-1][mid];
    }
    if(freq[n-1][mid]==0)
    {
        return freq[n-1][start];
    }
    int maxLength=0;
    for(int i=0;i<occ.size()/2;i++)
    {
        maxLength=max(maxLength,2*(i+1)+freq[occ[i]][mid]-freq[occ[occ.size()-1-i]][mid]);
    }
    return maxLength;
}
void set_freq(int f[][201],int n,int a[],int &maxL)
{
    for(int i=1;i<=200;i++)
    {
        f[0][i]=a[0]==i?1:0;
        maxL=max(maxL,f[0][i]);
    }
    for(int i=1;i<=200;i++)
    {
        for(int j=1;j<n;j++)
        {
            f[j][i]=a[j]==i?f[j-1][i]+1:f[j-1][i];
            maxL=max(maxL,f[j][i]);
            //cout<<"setted\n";
        }
    }
}
int main()
{
    int t;
    cin>>t;
    int n;
    while(t--)
    {
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int freq[n][201];
        int maxLength=0;
        set_freq(freq,n,a,maxLength);
        vector< vector<int> > occ(201);
        for(int i=0;i<n;i++)
        {
            occ[a[i]].push_back(i);
            //maxLength=max(maxLength,occ[a[i]]);
        }
        for(int extreme_number=1;extreme_number<201;extreme_number++)
        {
            for(int mid_number=extreme_number;mid_number<201;mid_number++)
            {
                maxLength=max(maxLength,three_block_length(extreme_number,mid_number,freq,a,n,occ[extreme_number]));
            }

        }
        cout<<maxLength<<"\n";
    }
    return 0;
}