#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T &b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T &b) {
  if (a > b) a = b;
}
const double pi = (double)acos(-1.0);
const double eps = (double)1e-8;
const int INF = (int)0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 10;
const int MAXM = (int)3e6 + 10;
int N;
int a[MAXN];
int s[222][MAXN];
void work() {
  int QvQ;
  scanf("%d", &QvQ);
  while (QvQ--) {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= 200; j++) {
        s[j][i] = s[j][i - 1];
      }
      s[a[i]][i]++;
    }
    int ans = 0;
    for (int i = 1; i <= 200; i++) {
      ans = max(ans, s[i][N]);
      int st = 0, en = N + 1, cnt = 0;
      while (st < en) {
        cnt++;
        st++;
        en--;
        while (st <= N && a[st] != i) st++;
        while (en >= 1 && a[en] != i) en--;
        if (st >= en) break;
        int tmp = 0;
        for (int k = 1; k <= 200; k++) {
          tmp = max(tmp, s[k][en - 1] - s[k][st]);
        }
        ans = max(ans, cnt * 2 + tmp);
      }
    }
    printf("%d\n", ans);
  }
}
int main() {
  work();
  return 0;
}
