#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int a[maxn], n;
int c[201][maxn];
int pre[maxn], nxt[maxn], p[201];
int last[maxn], first[maxn];
int find(int l, int r) {
  int ans = 0;
  for (int k = 1; k < 201; k++) {
    ans = max(ans, c[k][r] - c[k][l]);
  }
  return ans;
}
int main() {
  int T, i, k;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (k = 1; k < 201; k++) {
      for (i = 0; i <= n; i++) c[k][i] = 0;
    }
    for (i = 1; i < 201; i++) p[i] = 0;
    for (i = 1; i <= n; i++) {
      pre[i] = p[a[i]];
      p[a[i]] = i;
    }
    for (i = 1; i < 201; i++) last[i] = p[i];
    for (i = 1; i < 201; i++) p[i] = n + 1;
    for (i = n; i > 0; i--) {
      nxt[i] = p[a[i]];
      p[a[i]] = i;
    }
    for (i = 1; i < 201; i++) first[i] = p[i];
    for (i = 1; i <= n; i++) {
      for (k = 1; k < 201; k++) c[k][i] = c[k][i - 1];
      c[a[i]][i]++;
    }
    int ans = 1;
    for (k = 1; k < 201; k++) {
      int l = first[k], r = last[k];
      int t = 1;
      while (l < r) {
        ans = max(ans, t + t + find(l, r - 1));
        l = nxt[l];
        r = pre[r];
        t++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
