#include <bits/stdc++.h>
using namespace std;
int n, a[200005], pre[200005];
void solve() {
  vector<pair<pair<int, int>, int>> v;
  cin >> n;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < 201; i++) {
    int l = 0, r = n + 1, cnt = 0;
    while (1) {
      l++;
      r--;
      while (l <= n and a[l] != i) l++;
      while (r >= 1 and a[r] != i) r--;
      if (l >= r) break;
      cnt += 2;
      v.push_back({{l, r}, cnt});
    }
  }
  int ans = 1;
  for (int i = 1; i < 201; i++) {
    for (int j = 1; j < n + 1; j++) {
      if (a[j] == i) pre[j] = 1;
      pre[j] += pre[j - 1];
    }
    for (auto j : v) {
      ans = max(ans, j.second + pre[j.first.second - 1] - pre[j.first.first]);
    }
    for (int j = 1; j < n + 1; j++) pre[j] = 0;
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
