#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int i, j, k, n, ans = 0;
    cin >> n;
    vector<vector<int> > cnt(201, vector<int>(n + 2, 0));
    vector<vector<int> > pos(201);
    for (i = 1; i <= n; ++i) {
      cin >> j;
      cnt[j][i]++;
      pos[j].push_back(i);
    }
    for (i = 1; i <= 200; ++i) {
      for (j = 2; j <= n; ++j) cnt[i][j] += cnt[i][j - 1];
    }
    for (i = 1; i <= 200; ++i) {
      ans = max(ans, cnt[i][n]);
      for (j = 0; j < (pos[i].size() / 2); ++j) {
        int l = pos[i][j] + 1;
        int r = pos[i][pos[i].size() - j - 1] - 1;
        for (k = 1; k <= 200; ++k) {
          int sum = cnt[k][r] - cnt[k][l - 1];
          if (sum >= 0) ans = max(ans, (j + 1) * 2 + sum);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
