#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 205;
int n;
int a[N];
int sum[M][N];
vector<int> num[M];
int get_sum(int num, int l, int r) { return sum[num][r] - sum[num][l - 1]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= 200; i++) num[i].clear();
    for (int i = 1; i <= 200; i++)
      for (int j = 1; j <= n; j++) sum[i][j] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      num[a[i]].push_back(i);
      for (int j = 1; j <= 200; j++) sum[j][i] = sum[j][i - 1];
      sum[a[i]][i]++;
    }
    int ans = 1;
    for (int i = 1; i <= 200; i++) ans = max(ans, sum[i][n]);
    for (int i = 1; i <= 200; i++) {
      for (int j = 0; j < ((int)num[i].size()) / 2; j++) {
        int x = num[i][j], y = num[i][((int)num[i].size() - 1) - j], tmp = 0;
        if (x + 1 > y - 1) break;
        for (int k = 1; k <= 200; k++) tmp = max(tmp, get_sum(k, x + 1, y - 1));
        ans = max(ans, (j + 1) * 2 + tmp);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
