#include <bits/stdc++.h>
using namespace std;
void setup() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
long long modulo(long long a, long long m) { return ((a % m) + m) % m; }
int t, n, a[200005];
vector<int> inde[205];
int bins(int in, int v, int type) {
  int low = 0, high = (int)inde[v].size() - 1, mid, lowd = 1, highd = 1,
      midd = 0;
  if (type == 1) {
    lowd = 0;
    midd = 1;
  }
  if (type == 2) {
    highd = 0;
  }
  if (inde[v][0] > in) return 0;
  while (low < high) {
    mid = (low + high + midd) / 2;
    if (inde[v][mid] == in)
      return mid + 1;
    else if (inde[v][mid] < in)
      low = mid + lowd;
    else
      high = mid - highd;
  }
  return low + 1;
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    inde[a[i]].push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sz = (int)inde[a[i]].size();
    int k = bins(i, a[i], 0);
    int r = inde[a[i]][sz - k];
    int maxn = 0;
    for (int j = 1; j <= 200; j++) {
      if (a[i] != j && (int)inde[j].size()) {
        maxn = max(maxn, (bins(r, j, 1) - bins(i, j, 1)));
      }
    }
    if (i < r) ans = max(ans, maxn + 2 * k);
    if (i == r) ans = max(ans, 2 * k - 1);
  }
  cout << ans << endl;
  for (int i = 1; i <= 200; i++) {
    inde[i].clear();
  }
}
int main() {
  setup();
  cin >> t;
  for (int i = 0; i < t; i++) solve();
}
