#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int v[200002];
int frq[202];
int cnt[200002][202];
vector<int> pz[202];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (; t; --t) {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> v[i];
      ++frq[v[i]];
      ans = max(ans, frq[v[i]] - (1 - frq[v[i]] % 2));
      for (int j = 1; j <= 200; ++j) cnt[i][j] = cnt[i - 1][j] + (v[i] == j);
      pz[v[i]].push_back(i);
    }
    for (int i = 1; i <= 200; ++i)
      for (int sz = 1; sz <= n; ++sz)
        if (pz[i].size() >= 2 * sz) {
          int pza = pz[i][sz - 1];
          int pzb = pz[i][pz[i].size() - sz];
          int aa = 0;
          for (int x = 1; x <= 200; ++x)
            aa = max(aa, cnt[pzb - 1][x] - cnt[pza][x]);
          ans = max(ans, aa + 2 * sz);
        } else
          break;
    cout << ans << '\n';
    for (int i = 1; i <= 200; ++i) pz[i].clear();
    memset(frq, 0, sizeof(frq));
  }
  return 0;
}
