#include <bits/stdc++.h>
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    static int aa[200000], qu[200000], pp[200 + 1][200000];
    int n, h, i, a, b, cnt, ans;
    scanf("%d", &n);
    for (a = 1; a <= 200; a++) memset(pp[a], 0, n * sizeof *pp[a]);
    for (i = 0; i < n; i++) {
      scanf("%d", &a);
      aa[i] = a;
      pp[a][i] = 1;
    }
    for (a = 1; a <= 200; a++)
      for (i = 1; i < n; i++) pp[a][i] += pp[a][i - 1];
    ans = 0;
    for (a = 1; a <= 200; a++) {
      cnt = 0;
      for (i = 0; i < n; i++)
        if (aa[i] == a) qu[cnt++] = i;
      for (h = 0; h * 2 <= cnt; h++) {
        int l = h == 0 ? 0 : qu[h - 1] + 1,
            r = h == 0 ? n - 1 : qu[cnt - h] - 1;
        for (b = 1; b <= 200; b++)
          ans = max(ans, h * 2 + pp[b][r] - (l == 0 ? 0 : pp[b][l - 1]));
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
