#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const long long linf = 0x3f3f3f3f3f3f3f3f;
map<int, int> le[300], ri[300];
vector<int> pr[300], su[300];
int a[200100];
int f(int meio) {
  int r = 0;
  for (int i = 1; i <= 200; i++) {
    if (2 * meio > le[i].size()) continue;
    int x = pr[i][meio], y = su[i][meio];
    if (x == y) {
      r = max(r, 2 * meio - 1);
      continue;
    }
    for (int j = 1; j <= 200; j++) {
      auto it1 = le[j].lower_bound(x + 1);
      auto it2 = le[j].lower_bound(y);
      r = max(r, 2 * meio + (*it2).second - (*it1).second);
    }
  }
  return r;
}
int tsearch(int r) {
  int l = 0;
  while (r - l >= 7) {
    int mid = (r + l) / 2;
    if (f(mid) > f(mid + 1))
      r = mid + 1;
    else
      l = mid;
  }
  for (int i = l + 1; i <= r; ++i) {
    if (f(l) < f(i)) l = i;
  }
  return l;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    for (int i = 1; i <= 200; i++)
      le[i].clear(), ri[i].clear(), pr[i].clear(), su[i].clear();
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= 200; i++) {
      pr[i].push_back(0);
      su[i].push_back(n + 1);
    }
    for (int i = 1; i <= n; i++)
      le[a[i]][i] = le[a[i]].size(), pr[a[i]].push_back(i);
    for (int i = n; i >= 1; i--) su[a[i]].push_back(i);
    for (int i = 1; i <= 200; i++) {
      le[i][inf] = le[i].size();
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, f(i));
    printf("%d\n", ans);
  }
  return 0;
}
