#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n + 1);       for (int i = 1; i <= n; i++) cin >> a[i];       vector<vector<int> > dp(201);       for (int i = 1; i <= n; i++) {         dp[a[i]].push_back(i);       }       int maximum = 0;       for (int i = 1; i <= n; i++) {         int p = a[i];         int l = lower_bound(dp[p].begin(), dp[p].end(), i) - begin(dp[p]);         int r = dp[p].size() - l - 1;         if (l >= r) continue;         int lval = dp[p][l];         int rval = dp[p][r];         int maxi = 0;         for (int j = 1; j <= 200; j++) {           if (j == p) {             maxi = max(maxi, r - l - 1);             continue;           }           int xx = upper_bound(dp[j].begin(), dp[j].end(), rval) - dp[j].begin();           int yy = upper_bound(dp[j].begin(), dp[j].end(), lval) - dp[j].begin();           maxi = max(maxi, xx - yy);         }         maximum = max(maximum, maxi + (2 * (l + 1)));       }       cout << max(1, maximum) << endl;     }   }   