#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 5;
int pre[201][mxn];
int mp[201];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    int i, j, k, n, m;
    cin >> n;
    vector<int> a(n);
    for (i = 0; i < 201; i++) mp[i] = 0;
    for (i = 0; i < n; i++) cin >> a[i], mp[a[i]]++;
    vector<vector<int>> pos(201);
    for (i = 1; i < 201; i++) {
      m = 0;
      pos[i].emplace_back(-1);
      for (j = 0; j < n; j++) {
        if (a[j] == i) {
          m++;
          pos[i].emplace_back(j);
        }
        pre[i][j] = m;
      }
    }
    int ans = 0;
    for (int num = 1; num < 201; num++) {
      for (i = 0; i <= mp[num]; i++)
        if (2 * i <= mp[num]) {
          int tmp = 2 * i, z = 0;
          int l, r;
          if (i == 0)
            l = 0, r = n - 1;
          else
            l = pos[num][i] + 1, r = pos[num][mp[num] - i + 1] - 1;
          for (j = 1; j < 201; j++)
            if (l > 0)
              z = max(z, pre[j][r] - pre[j][l - 1]);
            else
              z = max(z, pre[j][r]);
          tmp += z;
          ans = max(ans, tmp);
        }
    }
    cout << ans << "\n";
  }
  return 0;
}
