#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], sum[maxn][205];
vector<int> v[205];
int main() {
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= 200; i++) v[i].clear();
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 200; j++) sum[i][j] = 0;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      v[a[i]].push_back(i);
      for (int j = 1; j <= 200; j++) sum[i][j] = sum[i - 1][j];
      sum[i][a[i]]++;
    }
    int ans = 0;
    for (int i = 1; i <= 200; i++) {
      int siz = v[i].size();
      if (!siz) continue;
      ans = max(ans, siz);
      for (int j = 0; j < siz; j++) {
        if (j + 1 > siz / 2) break;
        int tmp = 0;
        int l = v[i][j];
        int r = v[i][siz - j - 1];
        for (int k = 1; k <= 200; k++) {
          if (l == r - 1 || l == r) break;
          tmp = max(tmp, sum[r - 1][k] - sum[l][k]);
        }
        ans = max(ans, (j + 1) * 2 + tmp);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
