#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int M = 210;
int T, n, a[N], b[M][N], bn[M], c[N];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= 200; i++) bn[i] = 0;
    for (int i = n; i >= 1; i--) {
      bn[a[i]] += 1;
      b[a[i]][bn[a[i]]] = i;
    }
    int res = 0;
    for (int i = 1; i <= 200; i++) res = max(res, bn[i]);
    for (int i = 1; i <= 200; i++) {
      for (int j = 1; j <= n; j++) {
        if (a[j] == i)
          c[j] = c[j - 1] + 1;
        else
          c[j] = c[j - 1];
      }
      for (int j = 1; j <= 200; j++) {
        for (int k = 1; 2 * k <= bn[j]; k++) {
          int l = b[j][bn[j] - k + 1] + 1, r = b[j][k] - 1;
          res = max(res, 2 * k + c[r] - c[l - 1]);
        }
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
