#include <bits/stdc++.h>
using namespace std;
int a[200010];
int cnt[210];
int pref[200010][210];
int n;
int calc(int p1, int p2, int x) { return pref[p2][x] - pref[p1 - 1][x]; }
int binarna(int val, int x) {
  if (pref[n][x] < 2 * val) return -1;
  int l = 1;
  int r = n;
  while (l < r) {
    int sr = (l + r + 1) / 2;
    if (calc(sr, n, x) < val)
      r = sr - 1;
    else
      l = sr;
  }
  return l;
}
void resi() {
  memset(cnt, 0, sizeof(cnt));
  cin >> n;
  int maxV = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxV = max(maxV, a[i]);
    cnt[a[i]]++;
    for (int j = 1; j <= 200; j++) pref[i][j] = pref[i - 1][j];
    pref[i][a[i]]++;
  }
  int rez = 0;
  for (int i = 1; i <= maxV; i++) rez = max(rez, cnt[i]);
  for (int i = 1; i <= n; i++) {
    int vr = pref[i][a[i]];
    int index = binarna(vr, a[i]);
    if (index <= i) continue;
    int best = 0;
    for (int j = 1; j <= maxV; j++) {
      best = max(best, calc(i + 1, index - 1, j));
    }
    rez = max(rez, best + 2 * vr);
  }
  cout << rez << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) resi();
  return 0;
}
