#include <bits/stdc++.h>
using namespace std;
void printline(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
void printcol(vector<int> v) {
  for (auto x : v) cout << x << endl;
}
int psum[205][200005];
int calc(int L, int R, int letter) {
  return psum[letter][R] - psum[letter][L - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> pos[205];
    int v[n];
    for (int i = 0; i < n; i++) cin >> v[i], pos[v[i]].push_back(i);
    if (n == 1) {
      cout << 1 << endl;
      continue;
    } else if (n == 2) {
      if (v[0] == v[1])
        cout << 2 << endl;
      else
        cout << 1 << endl;
      continue;
    }
    for (int letter = 1; letter <= 201; letter++) {
      psum[letter][0] = v[0] == letter;
      for (int i = 1; i < n; i++)
        psum[letter][i] = psum[letter][i - 1] + (v[i] == letter);
    }
    int ans = 1;
    for (int letter = 1; letter <= 201; letter++) {
      for (int i = 0; i < (pos[letter].size() / 2); i++) {
        int left = pos[letter][i] + 1;
        int right = pos[letter][pos[letter].size() - i - 1] - 1;
        int qnt = 0;
        for (int middleLetter = 1; middleLetter <= 201; middleLetter++) {
          qnt = max(qnt, calc(left, right, middleLetter));
        }
        ans = max(ans, qnt + i + 1 + i + 1);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
