#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 1][200];
    memset(a, 0, sizeof(a));
    vector<int> v[200];
    for (long long i = 1; i < n + 1; i++) {
      int x;
      cin >> x;
      x--;
      a[i][x]++;
      v[x].push_back(i);
    }
    for (long long i = 0; i < 200; i++) {
      for (long long j = 1; j < n + 1; j++) a[j][i] += a[j - 1][i];
    }
    int ans = -1;
    for (long long i = 0; i < 200; i++) {
      ans = max(ans, (int)v[i].size());
      for (long long j = 0; j < v[i].size() / 2; j++) {
        int l = v[i][j] + 1, r = v[i][v[i].size() - j - 1] - 1;
        int val = -1;
        for (long long k = 0; k < 200; k++) {
          val = max(val, a[r][k] - a[l - 1][k]);
        }
        ans = max((long long)ans, val + 2 * (j + 1));
      }
    }
    cout << ans << "\n";
  }
}
