#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int B = 210;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<vector<int>> sum(n + 1, vector<int>(B, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];
    sum[i + 1][a[i]]++;
  }
  auto f = [&](int x) {
    int res = 0;
    int l = 0, r = n, val = 0;
    while (l < r) {
      while (l < n and sum[l][x] < val) l++;
      while (0 < r and sum[n][x] - sum[r][x] < val) r--;
      if (r <= l) break;
      int mid = 0;
      for (int i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);
      chmax(res, mid + sum[l][x] + sum[l][x]);
      val++;
    }
    return res;
  };
  int ans = 0;
  for (int i = 0; i < B; i++) chmax(ans, f(i));
  cout << ans << '\n';
  return;
}
int main() {
  int q;
  cin >> q;
  while (q--) solve();
  return 0;
}
