#include <bits/stdc++.h>
using namespace std;
template <class T>
bool read(T& ret) {
  char c;
  int sgn;
  T bit = 0.1;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && c != '.' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  if (c == ' ' || c == '\n') {
    ret *= sgn;
    return 1;
  }
  while (c = getchar(), c >= '0' && c <= '9') ret += (c - '0') * bit, bit /= 10;
  ret *= sgn;
  return 1;
}
int n, a[200010];
vector<int> ar[205];
void solve() {
  for (int i = 0; i < 205; i++) ar[i].clear();
  int ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], ar[a[i]].push_back(i);
  for (int i = 1; i <= 200; i++) {
    int l = ar[i].size() / 2, len = ar[i].size();
    ans = max(ans, len);
    if (len <= 1) continue;
    int num[206];
    memset(num, 0, sizeof(num));
    int d1 = ar[i][l - 1], d2 = ar[i][len - l];
    for (int j = d1 + 1; j < d2; j++) {
      num[a[j]]++;
    }
    int ma = 0;
    for (int i = 1; i <= 200; i++) {
      ma = max(ma, num[i]);
    }
    ans = max(ans, ma + l * 2);
    for (int j = l - 1; j > 0; j--) {
      for (int k = ar[i][j]; k > ar[i][j - 1]; k--) num[a[k]]++;
      for (int k = ar[i][len - j - 1]; k < ar[i][len - j]; k++) num[a[k]]++;
      for (int k = 1; k <= 200; k++) ma = max(ma, num[k]);
      ans = max(ans, ma + 2 * j);
    }
  }
  cout << ans << endl;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
