#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 6;
const int M = 1e9 + 7;
int A[N];
int mat[N][201];
int n;
void solve() {
  cin >> n;
  vector<vector<int> > vec(201);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 201; j++) mat[i][j] = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    mat[i][A[i]]++;
    vec[A[i]].push_back(i);
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 201; j++) {
      mat[i][j] += mat[i - 1][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 201; i++) {
    int l = vec[i].size();
    for (int j = 1; j < l / 2 + 1; j++) {
      int x = vec[i][j - 1];
      int y = vec[i][l - j];
      y--;
      int mx = 0;
      for (int k = 0; k < 201; k++) {
        mx = max(mx, mat[y][k] - mat[x][k]);
      }
      ans = max(ans, 2 * j + mx);
    }
  }
  if (n == 1 || ans == 0)
    ans = 1;
  else if (n == 2) {
    if (A[0] == A[1])
      ans = 2;
    else
      ans = 1;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
