#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
const int P = 998244353;
int n, a[N], p[201][N];
int best(int l, int r) {
  if (l > r) return 0;
  int mx = 0;
  for (int i = 1; i <= 200; i++) {
    mx = max(mx, p[i][r] - p[i][l - 1]);
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> v[201];
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      v[a[i]].push_back(i);
      for (int j = 1; j <= 200; j++) {
        p[j][i] = p[j][i - 1] + (a[i] == j);
      }
    }
    int ans = 0;
    for (int x = 1; x <= 200; x++)
      if ((int)v[x].size()) {
        ans = max(ans, (int)v[x].size());
        if ((int)v[x].size() < 2) continue;
        for (int k = 0; k < (int)v[x].size() / 2; k++) {
          int cu = (k + 1) * 2;
          cu += best(v[x][k] + 1, v[x][(int)v[x].size() - 1 - k] - 1);
          ans = max(ans, cu);
        }
      }
    cout << ans << '\n';
  }
}
