#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5, M = 205;
int t, n, ans, a[N], l[N][M];
void update(int i, int ai) {
  if (!i) l[i][ai] = 1;
  if (!i) return;
  for (int k = 1; k <= 200; k++) {
    l[i][k] = l[i - 1][k] + (k == ai);
  }
}
int get_cnt(int f, int b, int val) {
  if (f > b) return 0;
  if (!f) return l[b][val];
  return l[b][val] - l[f - 1][val];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0, j = n - 1; i < n; i++, j--) update(i, a[i]);
    ans = 0;
    for (int i = 1; i <= 200; i++) {
      int f = 0, b = n - 1, cf = 0, cb = 0, nxt = 1;
      bool ok1, ok2;
    _next:
      ok1 = 0, ok2 = 0;
      while (f <= b && cf != nxt) cf = l[f][i], f++, ok1 = 1;
      f -= ok1;
      while (b >= f && cb != nxt) cb = get_cnt(b, n - 1, i), b--, ok2 = 1;
      b += ok2;
      if (cf != nxt || cb != nxt) continue;
      for (int j = 1; j <= 200; j++) {
        ans = max(ans, l[f][i] + get_cnt(b, n - 1, i) - (b == f) +
                           get_cnt(f + 1, b - 1, j));
      }
      nxt++;
      goto _next;
    }
    for (int i = 0; i < n; i++)
      for (int j = 1; j <= 200; j++) l[i][j] = 0;
    cout << ans << '\n';
  }
  return 0;
}
