#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int pre[MAXN][200];
int a[MAXN];
vector<int> pos[205];
int main(void) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    memset(pre, 0, (n + 1) * sizeof(int) * 200);
    for (int i = 1; i <= 200; ++i) pos[i].clear();
    int res = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      pre[i][a[i]] = 1;
      for (int j = 1; j <= 200; ++j) pre[i][j] += pre[i - 1][j];
      res = max(res, pre[i][a[i]]);
      pos[a[i]].push_back(i);
    }
    for (int i = 1; i <= 200; ++i) {
      for (int j = 0; j < (int)pos[i].size() / 2; ++j) {
        int pl = pos[i][j];
        int pr = pos[i][(int)pos[i].size() - j - 1];
        for (int k = 1; k <= 200; ++k)
          res = max(res, 2 * (j + 1) + pre[pr - 1][k] - pre[pl][k]);
      }
    }
    cout << res << endl;
  }
  return 0;
}
