#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], i, j, ans = 1;
    int c[201][n + 1];
    vector<int> v[201];
    memset(c, 0, sizeof(c));
    for (i = 0; i < n; i++) {
      cin >> a[i];
      v[a[i]].push_back(i);
      c[a[i]][i + 1]++;
    }
    for (i = 1; i <= 200; i++) {
      for (j = 1; j <= n; j++) c[i][j] += c[i][j - 1];
      ans = max(ans, c[i][n]);
    }
    for (i = 1; i <= n / 2; i++) {
      for (j = 1; j <= 200; j++) {
        int l = v[j].size();
        if (2 * i <= l) {
          for (int k = 1; k <= 200; k++)
            ans = max(ans, 2 * i + c[k][v[j][l - i]] - c[k][v[j][i - 1] + 1]);
        }
      }
    }
    cout << ans << endl;
  }
}
