#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int pre[200005][200];
void blue() {
  cin >> n;
  vector<int> a(n + 2, 0);
  vector<int> occur[200];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i]--;
    occur[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    pre[i][a[i]]++;
    for (int j = 0; j < 200; j++) {
      pre[i][j] += pre[i - 1][j];
    }
  }
  int ans = 1;
  for (int i = 0; i < 200; i++) {
    for (int j = 0; j < occur[i].size() / 2; j++) {
      int l = occur[i][j] + 1;
      int r = occur[i][occur[i].size() - 1 - j] - 1;
      for (int k = 0; k < 200; k++) {
        ans = max(ans, 2 * (j + 1) + (pre[r][k] - pre[l - 1][k]));
      }
    }
  }
  cout << ans << "\n";
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < 200; j++) {
      pre[i][j] = 0;
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) blue();
}
