#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    int i, j;
    vector<vector<int> > cnt(201, vector<int>(n));
    vector<int> mp[201];
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      mp[arr[i]].push_back(i);
      cnt[arr[i]][i] = 1;
    }
    for (i = 1; i <= 200; i++) {
      for (j = 1; j < n; j++) {
        cnt[i][j] += cnt[i][j - 1];
      }
    }
    int ans = 1;
    for (i = 0; i < n; i++) {
      int count = cnt[arr[i]][i];
      if (mp[arr[i]].size() >= (2 * count)) {
        int pos_end = mp[arr[i]][(mp[arr[i]].size() - count)];
        pos_end--;
        int middle = 0;
        for (j = 1; j <= 200; j++) {
          middle = max(middle, cnt[j][pos_end] - cnt[j][i]);
        }
        ans = max(ans, 2 * count + middle);
      }
    }
    cout << ans << "\n";
  }
}
