#include <bits/stdc++.h>
using namespace std;
const int SIGMA = 200;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> A(n);
    for (auto& i : A) {
      cin >> i;
      i -= 1;
    }
    vector<vector<int>> partSum(SIGMA);
    vector<vector<int>> loc(SIGMA);
    for (int l = 0; l < SIGMA; ++l) {
      partSum[l].resize(n, 0);
      if (A[0] == l) {
        partSum[l][0] += 1;
        loc[l].push_back(0);
      }
      for (int i = 1; i < n; ++i) {
        partSum[l][i] = partSum[l][i - 1];
        if (A[i] == l) {
          partSum[l][i] += 1;
          loc[l].push_back(i);
        }
      }
    }
    int ans = 1;
    for (int l = 0; l < SIGMA; ++l) {
      int siz = loc[l].size();
      for (int i = 0; i < siz / 2; ++i) {
        for (int l2 = 0; l2 < SIGMA; ++l2) {
          if ((i + 1) * 2 + partSum[l2][loc[l][siz - 1 - i] - 1] -
                  partSum[l2][loc[l][i]] >
              ans)
            ans = (i + 1) * 2 + partSum[l2][loc[l][siz - 1 - i] - 1] -
                  partSum[l2][loc[l][i]];
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
