#include <bits/stdc++.h>
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5 + 10;
int c[210];
int a[maxn];
vector<int> pos[201];
int main() {
  int cas, n, t;
  cin >> cas;
  while (cas--) {
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= 200; i++) pos[i].clear();
    scanf("%d", &n);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      pos[a[i]].push_back(i);
      c[a[i]]++;
      ans = max(ans, c[a[i]] * 1ll);
    }
    for (int i = 1; i <= 200; i++) {
      int ci = 0;
      if (pos[i].size() < 2) continue;
      int en = pos[i].size() / 2 - 1;
      for (int j = 0; j <= en; j++) {
        int mx = 0;
        int l = pos[i][j], r = pos[i][pos[i].size() - 1 - j];
        for (int k = 1; k <= 200; k++) {
          if (k == i) continue;
          int pr =
              lower_bound(pos[k].begin(), pos[k].end(), r) - pos[k].begin();
          int pl =
              lower_bound(pos[k].begin(), pos[k].end(), l) - pos[k].begin();
          mx = max(mx, pr - pl);
        }
        ans = max(ans, mx + (j + 1) * 2ll);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
