#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = 205;
int a[M][N], y[N];
int main() {
  int n, t, ma, x, p, ox, op;
  scanf("%d", &t);
  while (t--) {
    ma = 1;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &y[i]);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j < M; j++) a[j][i] = a[j][i - 1];
      a[y[i]][i]++;
    }
    ox = op = 0;
    for (int i = n; i >= 1; i--) {
      int j = y[i];
      x = a[j][n] - a[j][i - 1];
      ox = max(ox, x);
      p = lower_bound(a[j] + 1, a[j] + i, x) - a[j];
      if (p == i) {
        continue;
      }
      int c = 0;
      for (int k = 1; k < M; k++) c = max(c, a[k][i - 1] - a[k][p]);
      ma = max(ma, x + x + c);
    }
    printf("%d\n", ma);
  }
  return 0;
}
