#include <bits/stdc++.h>
using namespace std;
void solve(int case_number) {
  int n;
  cin >> n;
  vector<int> ss(n);
  vector<vector<int>> nm(201, vector<int>(n, 0));
  for (int i = 0; i < n; i++) cin >> ss[i];
  for (int i = 0; i < n; i++)
    if (i == 0)
      nm[ss[i]][0] = 1;
    else
      for (int j = 1; j < 201; j++) nm[j][i] = nm[j][i - 1] + (j == ss[i]);
  int answer = 0;
  for (int i = 1; i < 201; i++) answer = max(answer, nm[i][n - 1]);
  for (int i = 0; i < n; i++) {
    if (nm[ss[i]][i] > nm[ss[i]][n - 1] / 2) continue;
    int index = upper_bound(nm[ss[i]].begin() + i + 1, nm[ss[i]].end(),
                            nm[ss[i]][n - 1] - nm[ss[i]][i]) -
                nm[ss[i]].begin();
    if (index == n) continue;
    int middle = 0;
    for (int j = 1; j < 201; j++)
      if (j != ss[i]) middle = max(middle, nm[j][index] - nm[j][i]);
    answer = max(answer, 2 * nm[ss[i]][i] + middle);
  }
  cout << answer << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int cases = 1;
  cin >> cases;
  for (int i = 0; i < cases; i++) solve(i + 1);
  return 0;
}
