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

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

    using namespace std;

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

    struct ends_range{
        ll count=0,ls=0,le=0,rs=0,re=0;
    };
    ll bin_search(ll *arr,ll n,ll val){
        ll mid,start=0,end=n-1;
        while(start<=end){
            //cout<<start<<" "<<end<<" "<<val<<endl;
            mid=ceil((start+end)/2.0);
            if(arr[mid]==val){
                if(mid==0) return mid;
                if(arr[mid-1]==val-1) return mid;
                end = mid-1;
            }else if(arr[mid]<val) start=mid+1;
            else end=mid-1;
        }
        return 0;
    }

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

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


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

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

    using namespace std;

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

    struct ends_range{
        l count=0,ls=0,le=0,rs=0,re=0;
    };
    l bin_search(l *arr,l n,l val){
        l mid,start=0,end=n-1;
        while(start<=end){
            //cout<<start<<" "<<end<<" "<<val<<endl;
            mid=ceil((start+end)/2.0);
            if(arr[mid]==val){
                if(mid==0) return mid;
                if(arr[mid-1]==val-1) return mid;
                end = mid-1;
            }else if(arr[mid]<val) start=mid+1;
            else end=mid-1;
        }
        return 0;
    }

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

            //prefixes
            l pre[200][n];
            fo(i,200) pre[i][0] = 0;
            pre[a[0]-1][0] = 1;
            for(j=1;j<n;j++){
                fo(i,200) pre[i][j] = pre[i][j-1];
                pre[a[j]-1][j]++;
            }
            /*fo(i,200){
                cout<<i+1<<": ";
                fo(j,n) cout<<pre[i][j]<<" ";
                cout<<endl;
            }*/
            ends_range er[200];
            fo(i,200){
                er[i].count = (pre[i][n-1]/2)*2;
                if(er[i].count<=1) continue;
                er[i].ls = bin_search(pre[i],n,1);
                er[i].le = bin_search(pre[i],n,er[i].count/2);
                er[i].re = bin_search(pre[i],n,ceil(pre[i][n-1]/2.0)+1);
                er[i].rs = bin_search(pre[i],n,pre[i][n-1]);
            }
            //fo(i,200) cout<<er[i].count<<" "<<er[i].ls<<" "<<er[i].le<<" "<<er[i].re<<" "<<er[i].rs<<endl;
            l max_count = 1;
            fo(k,200){
                //cout<<max_count<<endl;
                l cur_count = er[k].count;
                l start = er[k].le;
                l end = er[k].re;
                //cout<<cur_count<<" "<<start<<" "<<end<<endl;
                while(start>=0 and end<=n-1){
                    l count1 = 0;
                    if(start<end){
                        fo(i,200){
                            if(count1<(pre[i][end-1]-pre[i][start]))
                            count1 = pre[i][end-1]-pre[i][start];
                            //cout<<count1<<endl;
                        }
                    }
                    if(max_count<cur_count+count1)
                    max_count = cur_count+count1;
                    cur_count -= 2;
                    start--;
                    end++;
                    while(start>0 and a[start]!=k+1) start--;
                    while(end<n-1 and a[end]!=k+1) end++;
                }
            }
            cout<<max_count<<endl;
        }
    }


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

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

    using namespace std;

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

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

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

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

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

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

        }
    }


#include<bits/stdc++.h>

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

using namespace std;

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

int hr[100];
int formula[100][2];
ll quant[100];

long long int min(long long int a, long long int b){
    if(a<b) return a;
    return b;
}
void assign_hr(int m){
    int ing1=formula[m-1][0];
    int ing2=formula[m-1][1];
    //cout<<m<<" "<<hr[m-1]<<endl;

    int h = hr[m-1];
    bool up1=false,up2=false;
    if(!hr[ing1-1] and ing1!=1){
        hr[ing1-1]=h+1;
        up1 = true;
    }
    if(!hr[ing2-1]){
        hr[ing2-1] = h+1;
        up2=true;
    }
    if(up1) assign_hr(ing1);
    if(up2) assign_hr(ing2);
}

ll make(int m,int M){
    if(M==0) return 0;
    M--;
    ll prod = 0;
    int ing1=formula[m-1][0],ing2=formula[m-1][1];

    //cout<<hr[m-1]<<" "<<hr[ing1-1]<<" "<<hr[ing2-1]<<endl;
    //if(hr[m-1]>hr[ing1-1] or hr[m-1]>hr[ing2-1]) return prod;

    if(quant[ing1-1]==0)
        quant[ing1-1]+=make(ing1,M);
    if(quant[ing2-1]==0)
        quant[ing2-1]+=make(ing2,M);
    if(!(quant[ing1-1] and quant[ing2-1])) return 0;

    prod = 1;

    quant[ing1-1] -= prod;
    quant[ing2-1] -= prod;
    return prod;
}

int main(){
    int T;
    cin>>T;
    for(int t=1;t<=T;t++){
        int M,i,j,k;
        fo(i,100) hr[i]=0;
        cin>>M;
        fo(i,M) cin>>formula[i][0]>>formula[i][1];
        fo(i,M) cin>>quant[i];

        //assign_hr(1);

        ll prod = quant[0];
        quant[0] = 0;
        int ing1 = formula[0][0],ing2=formula[0][1];

        ll cr_prod=0;
        while(cr_prod = make(1,M+1)){
            prod+= cr_prod;
        }

        cout<<"Case #"<<t<<": "<<prod;
        if(T!=t) cout<<endl;
    }
}


 #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 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 (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 sot(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 100010
#define MOD 1000000007
#define MOD1 998244353
#define print(x) {  \
             cout<<x<<endl; \
             cerr<<endl; \
             return;    \
}
#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 % 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;
const ll maxn=200001;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[201][maxn];
   vector<ll> as[201];
   //vector<ll> sa[205];
   ll ar[maxn];
void allclear(ll n){
    rep(i,201){
        rep(j,n){
            fa[i][j]=0;
        }
        if((ll)as[i].size()>0)
        as[i].clear();
     //   sa[i].clear();
    }
}

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<fixed;
    cout<<setprecision(9);

    ll txt;
    cin>>txt;
    while(txt--){
    ll n;
    cin>>n;

  // vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,201){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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,201){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       ll sz=as[ar[i]].size();
       r=as[ar[i]][sz-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,201){
           ll cc=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

    }
    return 0;
}


#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;

const ll maxn=200010;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[205][maxn];
   vector<ll> as[205];
   vector<ll> sa[205];

void allclear(ll n){
    rep(i,205){
        rep(j,n){
            fa[i][j]=0;
        }
        as[i].clear();
        sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

   vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,203){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       r=sa[ar[i]][c]-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=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}


#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<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   vector<ll> as[205];
   vector<ll> sa[205];
   vector<ll> ar(n);

   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,203){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       r=sa[ar[i]][c]-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=fa[j][r]-fa[j][l-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;
}


#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;

// 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;

ll n,m;
const ll maxn=200001;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[201][maxn];
   vector<ll> as[201];
   //vector<ll> sa[205];
   ll ar[maxn];
void allclear(ll n){
    rep(i,201){
        rep(j,n){
            fa[i][j]=0;
        }
        if((ll)as[i].size()>0)
        as[i].clear();
     //   sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

  // vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,201){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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,201){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       ll sz=as[ar[i]].size();
       r=as[ar[i]][sz-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,201){
           ll cc=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}


#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;

const ll maxn=200001;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[201][maxn];
   vector<ll> as[201];
   //vector<ll> sa[205];
   ll ar[maxn];
void allclear(ll n){
    rep(i,201){
        rep(j,n){
            fa[i][j]=0;
        }
        if((ll)as[i].size()>0)
        as[i].clear();
     //   sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

  // vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,201){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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,201){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       ll sz=as[ar[i]].size();
       r=as[ar[i]][sz-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,201){
           ll cc=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}


#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;

const ll maxn=200001;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[201][maxn];
   vector<ll> as[201];
   //vector<ll> sa[205];

void allclear(ll n){
    rep(i,201){
        rep(j,n){
            fa[i][j]=0;
        }
        if((ll)as[i].size()>0)
        as[i].clear();
     //   sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

   vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,201){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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,201){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       ll sz=as[ar[i]].size();
       r=as[ar[i]][sz-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,201){
           ll cc=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}


#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;

const ll maxn=200010;
vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   vector<ll> as[205];
   vector<ll> sa[205];

void allclear(ll n){
    rep(i,205){
        rep(j,n){
            fa[i][j]=0;
        }
        as[i].clear();
        sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

   vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,203){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       r=sa[ar[i]][c]-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=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}


#include <bits/stdc++.h>
#include <functional> // for less
#include <iostream>
#define ll int
#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;

// 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;

ll n,m;
const ll maxn=200001;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[201][maxn];
   vector<ll> as[201];
   //vector<ll> sa[205];
   ll ar[maxn];
void allclear(ll n){
    rep(i,201){
        rep(j,n){
            fa[i][j]=0;
        }
        if((ll)as[i].size()>0)
        as[i].clear();
     //   sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

  // vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,201){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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,201){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       ll sz=as[ar[i]].size();
       r=as[ar[i]][sz-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,201){
           ll cc=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}


#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);
   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);
   }
   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;
}


#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;
}

//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;

const ll maxn=200001;
//vector<vector<ll>> fa(205,vector<ll>(maxn));
   //vector<vector<ll>> af(205,vector<ll>(n));
   //vector<vector<ll>> fa(200,vector<ll>(205));
   ll fa[201][maxn];
   vector<ll> as[201];
   //vector<ll> sa[205];
   ll ar[maxn];
void allclear(ll n){
    rep(i,201){
        rep(j,n){
            fa[i][j]=0;
        }
        if((ll)as[i].size()>0)
        as[i].clear();
     //   sa[i].clear();
    }
}

void neuer(ll txt)
{
   cin>>n;

  // vector<ll> ar(n);
   rep(i,n){
       cin>>ar[i];
       if(i==0){
           fa[ar[i]][i]++;
       }
       else
       {
           fa[ar[i]][i]++;
           rep(j,201){
               fa[j][i]+=fa[j][i-1];
           }
       }
       as[ar[i]].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,201){
           mx=max(mx,fa[j][n-1]);
       }
       //debug(mx);

   rep(i,n){
       ll l,r;
       ll c=fa[ar[i]][i];
       c--;
       //dbug(ar[i]); debug(c);
       l=as[ar[i]][c]+1;
       ll sz=as[ar[i]].size();
       r=as[ar[i]][sz-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,201){
           ll cc=fa[j][r]-fa[j][l-1];
           ma=max(cc,ma);
       }
       c++;
       ll la=c*2+ma;
       mx=max(mx,la);
   }
   cout<<(mx)<<endl;
   cerr<<endl;
    allclear(n);

   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;
}