#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int cnt[N][201];
int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i <= n + 1; i++) {
      for (int j = 0; j <= 200; j++) cnt[i][j] = 0;
    }
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 200; j++) {
        if (j == a[i])
          cnt[i][j] = cnt[i - 1][j] + 1;
        else
          cnt[i][j] = cnt[i - 1][j];
      }
    }
    int ans = 1;
    for (int i = 1; i <= n; i++) {
      int freqTillFar = cnt[i][a[i]];
      int totalFreq = cnt[n][a[i]];
      int limit = totalFreq / 2;
      if (freqTillFar <= limit) {
        int low = i + 1;
        int high = n;
        int r = -1;
        while (low <= high) {
          int mid = (low + high) / 2;
          int f = cnt[n][a[i]] - cnt[mid - 1][a[i]];
          if (f < freqTillFar) {
            high = mid - 1;
          } else {
            r = mid;
            low = mid + 1;
          }
        }
        int cc = 0;
        for (int x = 1; x <= 200; x++) {
          cc = max(cc, cnt[r - 1][x] - cnt[i][x]);
        }
        ans = max(ans, cc + 2 * freqTillFar);
      }
    }
    cout << ans << "\n";
  }
}
