#include <bits/stdc++.h>
using namespace std;
vector<int> a, s[201];
int n;
int bs(int pos, int x) {
  int left = pos + 1, right = n, mid, k = a[pos], res = -1;
  while (left <= right) {
    mid = (left + right) >> 1;
    if (s[k][n] - s[k][mid - 1] >= x) {
      res = mid;
      left = mid + 1;
    } else
      right = mid - 1;
  }
  if (res != -1) {
    if (s[k][n] - s[k][res - 1] != x) res = -1;
  }
  return res;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    int ans = 1;
    cin >> n;
    a.resize(n + 1, 0);
    for (int i = 0; i <= 200; ++i) s[i].resize(n + 1, 0);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= 200; ++j) s[j][i] = s[j][i - 1] + (a[i] == j);
    }
    for (int i = 1; i <= n; ++i) {
      int j = bs(i, s[a[i]][i]), res = 0;
      if (j == -1) continue;
      for (int k = 1; k <= 200; ++k) res = max(res, s[k][j - 1] - s[k][i]);
      ans = max(ans, res + 2 * s[a[i]][i]);
    }
    cout << ans << "\n";
  }
  return 0;
}
