#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int> > pre(200, vector<int>(n + 1));
    vector<vector<int> > posi(200);
    vector<int> ary(n);
    int ans = 0;
    for (int i = 0; i <= n - 1; i++) {
      cin >> ary[i];
    }
    for (int i = 0; i <= n - 1; i++) {
      for (int j = 0; j <= 199; j++) {
        pre[j][i + 1] = pre[j][i];
      }
      pre[ary[i] - 1][i + 1]++;
      posi[ary[i] - 1].push_back(i);
    }
    for (int i = 0; i <= 199; i++) {
      int temp = posi[i].size();
      ans = max(ans, temp);
      for (int j = 0; j <= (temp / 2) - 1; j++) {
        int t1 = j + 1, t2 = INT_MIN;
        int l = posi[i][j] + 1, r = posi[i][temp - j - 1] - 1;
        for (int k = 0; k <= 199; k++) {
          t2 = max(t2, pre[k][r + 1] - pre[k][l]);
        }
        ans = max(ans, (t1)*2 + t2);
      }
    }
    cout << ans << endl;
  }
}
