#include <bits/stdc++.h>
using namespace std;
double eps = (double)1 / 1e6;
int inf = INT_MAX, mod2 = 998244353, mod1 = 1e9 + 7;
int sqr(int a) { return a * a; }
int qb(int a) { return a * a * a; }
int gcd(int a, int b) { return !a ? b : gcd(b % a, a); }
int binpow(int a, int b, int mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
int binmult(int a, int b, int mod) {
  return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod
                    : (2 * binmult(a, b / 2, mod)) % mod)
           : 0;
}
const int R = 1e4;
const int tx[4] = {0, 0, -1, 1};
const int ty[4] = {-1, 1, 0, 0};
const char rev_to[4] = {'E', 'W', 'N', 'S'};
const int N = 1e5 + 1;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> cnt(201, 0);
    vector<int> a(n);
    vector<vector<int>> mda(201, vector<int>());
    for (auto &z : a) cin >> z;
    for (int i = 0; i < n; i++) {
      cnt[a[i]]++;
      mda[a[i]].push_back(i);
    }
    int mx = 1;
    for (int x = 0; x <= 200; x++) {
      for (int le = 0; le < (int)mda[x].size() / 2; le++) {
        for (int y = 0; y <= 200; y++) {
          int first = upper_bound(mda[y].begin(), mda[y].end(), mda[x][le]) -
                      mda[y].begin();
          int second = lower_bound(mda[y].begin(), mda[y].end(),
                                   mda[x][(int)mda[x].size() - le - 1]) -
                       mda[y].begin();
          mx = max(mx, (le + 1) * 2 + (second - first));
        }
      }
    }
    cout << mx << "\n";
  }
  return 0;
}
