#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > sum, pos;
int main(void) {
  const int N = 200000;
  const int K = 200;
  sum.assign(K, vector<int>(N + 1, 0));
  int t;
  cin >> t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    pos.assign(K, vector<int>());
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      for (int j = 0; j < K; j++) sum[j][i] = sum[j][i - 1];
      sum[--a][i]++;
      pos[a].push_back(i);
    }
    for (int j = 0; j < K; j++) {
      int li = 0, ri = pos[j].size() - 1;
      int lft, rit;
      for (int i = 1; li < ri; i++) {
        lft = pos[j][li];
        rit = pos[j][ri];
        for (int k = 0; k < K; k++)
          ans = max(ans, i * 2 + sum[k][rit - 1] - sum[k][lft]);
        ++li;
        --ri;
      }
      ans = max(ans, sum[j][n]);
    }
    cout << ans << endl;
  }
}
