#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n + 5];
  vector<int> mx[201];
  for (long long int i = 1; i < n + 1; i++) {
    cin >> a[i];
    mx[a[i]].push_back(i);
  }
  int cnt[n + 1][201];
  memset(cnt, 0, sizeof cnt);
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 0; j < 201; j++) cnt[i][j] = cnt[i - 1][j];
    cnt[i][a[i]]++;
  }
  int ans = 0;
  for (long long int i = 1; i < n + 1; i++) {
    ans = max(ans, (int)mx[a[i]].size());
    for (long long int j = 1; j < 201; j++) {
      int x = min(cnt[n][j] - cnt[i][j], cnt[i - 1][j]);
      if (x == 0) continue;
      int t = (long long int)mx[j].size();
      int p1 = mx[j][t - x];
      int p2 = mx[j][x - 1];
      ans = max(ans, 2 * x + cnt[p1 - 1][a[i]] - cnt[p2][a[i]]);
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    solve();
  }
  return 0;
}
