#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
bool comp(pair<long long, long long> p, pair<long long, long long> q) {
  if (p.first != q.first)
    return p.first < q.first;
  else
    return p.second > q.second;
}
long long power(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) res = (res % mod * a % mod) % mod;
    a = (a % mod * a % mod) % mod;
    n /= 2;
  }
  return res % mod;
}
long long kmp(string x, long long m) {
  vector<long long> pi(m, 0);
  pi[0] = 0;
  long long ma = 0;
  long long j = 0;
  for (long long i = 1; i < m; i++) {
    while (j > 0 && x[i] != x[j]) j = pi[j - 1];
    if (x[j] == x[i]) j++;
    pi[i] = j;
  }
  return j;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n + 1], ma = 1;
    long long f[201];
    memset(f, 0, sizeof(f));
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
      f[a[i]]++;
      ma = max(ma, f[a[i]]);
    }
    for (long long i = 1; i <= 200; i++) {
      long long j = 1, k = n, c = 0;
      long long d[201] = {0};
      while (j < k) {
        long long md = 0;
        while (j <= n && a[j] != i) {
          d[a[j]]++;
          j++;
        }
        while (k >= 1 && a[k] != i) {
          d[a[k]]++;
          k--;
        }
        if (j >= k) break;
        d[i] += 2;
        c++;
        for (long long h = 1; h <= 200; h++) md = max(md, f[h] - d[h]);
        ma = max(ma, 2 * c + md);
        j++;
        k--;
      }
    }
    cout << ma << "\n";
  }
  return 0;
}
