#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i, j, n, ans = 1;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  int pref[n + 1][201];
  memset(pref, 0, sizeof(pref));
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 201; j++) pref[i][j] = pref[i - 1][j];
    pref[i][a[i - 1]]++;
  }
  for (i = 0; i < 201; i++) ans = max(ans, pref[n][i]);
  for (i = 1; i <= n; i++) {
    int x = a[i - 1];
    int val = pref[i][x];
    int l = i + 1, r = n, m;
    int pos = -1;
    while (l <= r) {
      m = (l + r) / 2;
      if (pref[n][x] - pref[m - 1][x] >= val) {
        pos = m;
        l = m + 1;
      } else
        r = m - 1;
    }
    if (pos == -1) continue;
    int mx = 0;
    for (j = 0; j < 201; j++) mx = max(mx, pref[pos - 1][j] - pref[i][j]);
    ans = max(ans, mx + 2 * val);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int test = 1;
  cin >> test;
  while (test--) solve();
}
