#include <bits/stdc++.h>
using namespace std;
int prefix[200001][201];
int t;
int binarySearch(int l, int r, int k, int x) {
  if (r >= l) {
    int mid = l + (r - l) / 2;
    if (prefix[mid][k] == x) {
      t = mid;
    }
    if (prefix[mid][k] > x) {
      return binarySearch(l, mid - 1, k, x);
    } else {
      return binarySearch(mid + 1, r, k, x);
    }
  }
  return t;
}
int main() {
  int t1;
  cin >> t1;
  for (int w = 0; w < t1; w++) {
    int n;
    cin >> n;
    int a[n];
    int ans = 1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 200; j++) {
        if (i == 0) {
          if (a[i] == j) {
            prefix[i][j] = 1;
          } else {
            prefix[i][j] = 0;
          }
        } else {
          if (a[i] == j) {
            prefix[i][j] = 1 + prefix[i - 1][j];
          } else {
            prefix[i][j] = prefix[i - 1][j];
          }
        }
      }
    }
    for (int k = 1; k <= 200; k++) {
      ans = max(prefix[n - 1][k], ans);
    }
    for (int i = 0; i < n; i++) {
      int x1 = prefix[i][a[i]];
      if (x1 > 0 && 2 * x1 <= prefix[n - 1][a[i]]) {
        int j = binarySearch(0, n - 1, a[i], prefix[n - 1][a[i]] - x1);
        int x2 = 0;
        for (int k = 1; k <= 200; k++) {
          x2 = max(prefix[j][k] - prefix[i][k], x2);
        }
        ans = max(x1 + x2 + x1, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
