#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using piii = pair<pair<int, int>, int>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
void getPrimes(int n, vector<int>& ans) {
  vector<bool> prime(n + 1, true);
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int i = (2); i < (prime.size()); i++) {
    if (prime[i]) ans.push_back(i);
  }
}
void solve() {
  int n;
  cin >> n;
  vi a(n);
  vvi pos(201);
  for (int i = (0); i < (n); i++) cin >> a[i];
  int pref[201][n];
  memset(pref, 0, sizeof(pref));
  for (int i = (0); i < (n); i++) {
    pref[a[i]][i]++;
    pos[a[i]].push_back(i);
  }
  for (int i = (1); i < (201); i++) {
    for (int j = (1); j < (n); j++) {
      pref[i][j] += pref[i][j - 1];
    }
  }
  int ans = 0;
  for (int k = (1); k < (201); k++) {
    ans = max(ans, pref[k][n - 1]);
    int sz = pos[k].size();
    for (int i = (0); i < (sz / 2); i++) {
      int x = 0, y = 0;
      x = i + 1;
      int l = pos[k][i], r = pos[k][sz - i - 1] - 1;
      for (int j = (1); j < (201); j++) {
        y = max(y, pref[j][r] - pref[j][l]);
      }
      ans = max(ans, y + 2 * x);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
