#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  int ct = 0;
  while (ct++ < t) {
    int n;
    cin >> n;
    vector<vector<int> > pos(201);
    vector<vector<int> > psum(201, vector<int>(n + 1));
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      pos[a].push_back(i);
      psum[a][i] += 1;
    };
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= 200; j++) psum[j][i] += psum[j][i - 1];
    int ans = 1;
    for (int i = 1; i <= 200; i++) {
      int sze = pos[i].size();
      for (int j = 0; j < sze / 2; j++) {
        int l = pos[i][j] + 1, r = pos[i][sze - j - 1] - 1;
        for (int k = 1; k <= 200; k++) {
          ans = max(ans, ((j + 1) << 1) + psum[k][r] - psum[k][l - 1]);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
