#include <bits/stdc++.h>
using namespace std;
long long int MAX3(long long int x, long long int y, long long int z) {
  long long int t = max(x, y);
  return max(t, z);
}
void solve() {
  int n, i, x, j;
  cin >> n;
  vector<vector<int>> pre(201, vector<int>(n + 1));
  vector<vector<int>> pos(201);
  int ans = 0;
  for (i = 1; i <= (n); i += 1) {
    cin >> x;
    pos[x].push_back(i - 1);
    for (j = 1; j <= (200); j += 1) {
      pre[j][i] = pre[j][i - 1];
    }
    pre[x][i] += 1;
  }
  int l, r, p;
  int cntout = 0;
  int cntin = 0;
  for (i = 1; i <= (200); i += 1) {
    ans = max(ans, (int)(pos[i].size()));
    for (p = 0; p < (((int)(pos[i].size())) / 2); p += 1) {
      l = pos[i][p] + 1;
      r = pos[i][(int)(pos[i].size()) - p - 1] - 1;
      for (j = 1; j <= (200); j += 1) {
        int sum = pre[j][r + 1] - pre[j][l];
        ans = max(ans, (p + 1) * 2 + sum);
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
