#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, 0, 0, 1, 1, 1, -1, -1};
const int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void solve() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> pos[201];
  vector<vector<int>> cnt(201, vector<int>(n + 1));
  for (i = 0; i < n; i++) {
    for (int j = 0; j <= 200; j++) {
      cnt[j][i + 1] = cnt[j][i];
    }
    cnt[a[i]][i + 1]++;
    pos[a[i]].push_back(i);
  }
  int ans = 0;
  for (i = 1; i <= 200; i++) {
    ans = max(ans, (int)pos[i].size());
  }
  for (i = 1; i <= 200; i++) {
    int len = pos[i].size();
    for (int j = 0; j < len / 2; j++) {
      int l = pos[i][j] + 1;
      int r = pos[i][len - 1 - j] - 1;
      for (int ij = 1; ij <= 200; ij++) {
        int sum = cnt[ij][r + 1] - cnt[ij][l];
        ans = max(ans, ((j + 1) * 2 + sum));
      }
    }
  }
  cout << ans << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  for (int j = 1; j <= tc; j++) {
    solve();
  }
  return 0;
}
