#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 200;
int cnt[N];
int a[N];
int n;
int calc(int x) {
  for (int i = 1; i <= 200; i++) cnt[i] = 0;
  for (int i = 1; i <= n; i++) cnt[a[i]]++;
  priority_queue<pair<int, int> > que;
  int ans = 0;
  for (int i = 1; i <= 200; i++) {
    que.push({cnt[i], i});
    ans = max(ans, cnt[i]);
  }
  int L = 1, R = n;
  int t = 0;
  while (L < R) {
    while (L <= n && a[L] != x) {
      cnt[a[L]]--;
      L++;
    }
    while (R > 0 && a[R] != x) {
      cnt[a[R]]--;
      R--;
    }
    if (L >= R) break;
    cnt[x] -= 2;
    L++, R--;
    t += 2;
    while (cnt[que.top().second] != que.top().first) {
      int y = que.top().second;
      que.pop();
      que.push({cnt[y], y});
    }
    ans = max(ans, t + que.top().first);
  }
  return ans;
}
void solve() {
  int ans = 0;
  for (int i = 1; i <= 200; i++) {
    ans = max(ans, calc(i));
  }
  printf("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    solve();
  }
  return 0;
}
