#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3f;
const int NINF = -INF - 1;
const long long int mod = 1e9 + 7;
int t, n, a[MAXN];
int pre[210][MAXN];
vector<int> vec[210];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= 200; i++) vec[i].clear();
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      vec[a[i]].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 200; j++) pre[j][i] = pre[j][i - 1];
      pre[a[i]][i]++;
    }
    int res = 1;
    for (int i = 1; i <= 200; i++) {
      int l = 0, r = vec[i].size() - 1;
      int ans = 0, left, right;
      while (l < r) {
        left = vec[i][l], right = vec[i][r];
        ans += 2;
        for (int j = 1; j <= 200; j++) {
          res = max(res, ans + pre[j][right - 1] - pre[j][left]);
        }
        l++, r--;
      }
    }
    cout << res << endl;
  }
  return 0;
}
