#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
set<int> s;
int DP[MAXN][205];
int A[MAXN];
vector<int> P[205];
int MAX(int I, int F) {
  int ret = 0;
  for (auto i : s) {
    ret = max(ret, DP[F][i] - DP[I - 1][i]);
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    for (int i = 1; i <= 200; i++) P[i].clear();
    s.clear();
    for (int i = 1; i <= N; i++) {
      cin >> A[i];
      s.insert(A[i]);
      P[A[i]].push_back(i);
    }
    for (auto i : s) {
      for (int j = 1; j <= N; j++) {
        DP[j][i] = DP[j - 1][i];
        if (A[j] == i) DP[j][i]++;
      }
    }
    int sol = 0;
    for (auto i : s) {
      int sz = P[i].size();
      for (int j = 0; j < sz; j++) {
        int I = P[i][j], F = P[i][sz - 1 - j];
        if (I > F) break;
        int val = 2 * (j + 1) + MAX(I + 1, F - 1);
        if (I == F) val--;
        sol = max(sol, val);
      }
    }
    cout << sol << '\n';
  }
  return 0;
}
