#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], s[205][maxn];
vector<int> vv[205];
int solve() {
  int n, mx(0);
  scanf("%d", &n);
  for (int i = 1; i < 201; ++i)
    for (int j = 1; j < n + 1; ++j) s[i][j] = 0;
  for (int i = 1; i < 201; ++i) vv[i].clear();
  for (int i = 1; i < n + 1; ++i) {
    scanf("%d", &a[i]);
    s[a[i]][i]++;
    vv[a[i]].push_back(i);
    for (int j = 1; j < 201; ++j) s[j][i] += s[j][i - 1];
  }
  for (int i = 1; i < 201; ++i) {
    int sz = vv[i].size();
    for (int j = 1; j < sz / 2 + 1; ++j) {
      int l = vv[i][j - 1] + 1, r = vv[i][sz - j] - 1, t(0);
      for (int k = 1; k < 201; ++k) t = max(t, s[k][r] - s[k][l - 1]);
      mx = max(mx, j * 2 + t);
    }
  }
  return printf("%d\n", mx ? mx : 1);
}
int main() {
  int _;
  scanf("%d", &_);
  while (_--) solve();
}
