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