#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433;
const long long M = 998244353;
int t, n, a[200100], ans, p, k, g, dd[202][200100];
pair<int, int> pp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  while (t--) {
    cin >> n;
    int b[202] = {}, c[202] = {}, d[202] = {};
    set<pair<int, int>> s[202];
    vector<int> v;
    ans = 0;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
      b[a[i]]++;
      ans = max(ans, b[a[i]]);
      if (b[a[i]] == 1) v.push_back(a[i]);
    }
    for (long long i = 1; i <= n; i++) {
      dd[a[i]][b[a[i]] - c[a[i]]] = i;
      c[a[i]]++;
      s[a[i]].insert({i, c[a[i]]});
    }
    for (auto i : v) {
      s[i].insert({0, 0});
      s[i].insert({1e9, 0});
    }
    for (long long i = 1; i <= n; i++) {
      d[a[i]]++;
      p = dd[a[i]][d[a[i]]];
      if (p <= i) continue;
      for (auto j : v) {
        if (j == a[i] || b[j] - d[j] + 2 * d[a[i]] <= ans) continue;
        pp = *prev(s[j].upper_bound({p, 0}));
        if (pp.first >= p) continue;
        g = pp.second;
        ans = max(ans, d[a[i]] * 2 + g - d[j]);
      }
    }
    cout << ans << "\n";
  }
}
