#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n;
int a[200005];
int fst[205];
int lst[205];
int nxt[200005];
int pre[200005];
int cnt[200005][200];
int cal(int x, int y) {
  int L = fst[x], R = lst[x];
  if (L == 0 || R == 0 || L == R) return 0;
  if (fst[y] == 0 || lst[y] == 0) return 0;
  int ans = 0;
  int cntL = 0, cntR = 0;
  while (L < R) {
    cntL += 1;
    cntR += 1;
    ans = max(ans, cntL + cntR + (cnt[R - 1][y] - cnt[L][y]));
    L = nxt[L];
    R = pre[R];
  }
  return ans;
}
void solve() {
  scanf("%d", &n);
  for (int k = 1; k <= 200; ++k) {
    lst[k] = 0;
    fst[k] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    pre[i] = 0;
    nxt[i] = n + 1;
    for (int k = 1; k <= 200; ++k) cnt[i][k] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    for (int k = 1; k <= 200; ++k) cnt[i][k] = cnt[i - 1][k];
    cnt[i][a[i]] += 1;
    if (lst[a[i]]) {
      nxt[lst[a[i]]] = i;
      pre[i] = lst[a[i]];
    }
    lst[a[i]] = i;
    if (fst[a[i]] == 0) fst[a[i]] = i;
  }
  int ans = 0;
  for (int k = 1; k <= 200; ++k) ans = max(ans, cnt[n][k]);
  for (int x = 1; x <= 200; ++x) {
    for (int y = 1; y <= 200; ++y) {
      if (y == x) continue;
      ans = max(ans, cal(x, y));
    }
  }
  printf("%d\n", ans);
}
int main() {
  int T = 1;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
