#include <bits/stdc++.h>
using namespace std;
vector<int> pos[202];
int cnt[202][200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, j, l, n, t, x, y, z, ans;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 1; i <= 200; i++) {
      pos[i].clear();
      for (j = 1; j <= n; j++) cnt[i][j] = 0;
    }
    vector<int> v;
    map<int, bool> mp;
    for (i = 1; i <= n; i++) {
      cin >> x;
      ++cnt[x][i];
      pos[x].emplace_back(i);
      for (j = 1; j < 201; j++) cnt[j][i] += cnt[j][i - 1];
      if (mp.find(x) == mp.end()) v.emplace_back(x), mp[x] = 1;
    }
    ans = 1;
    for (int x : v) {
      l = pos[x].size();
      for (i = 0; i < l / 2; i++) {
        z = 0;
        for (int bal : v)
          z = max(z, cnt[bal][pos[x][l - i - 1] - 1] - cnt[bal][pos[x][i]]);
        ans = max(ans, 2 * (i + 1) + z);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
