#include <bits/stdc++.h>
using namespace std;
const int N = 200010, mod = 1e9 + 7, INF = 0x3f3f3f3f;
const double eps = 1e-6;
int n;
int a[N], pos[N];
int pre[N][210];
vector<int> v[210];
int solve() {
  int ans = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 200; j++)
      pre[i][j] = pre[i - 1][j] + (a[i] == j), ans = max(ans, pre[i][j]);
  for (int i = 1; i <= n; i++) {
    int val = a[i];
    pos[val]++;
    if (pos[val] * 2 > (int)v[val].size()) continue;
    int cnt = pos[val] * 2;
    int st = i + 1, ed = v[val][v[val].size() - pos[val]] - 1;
    int add = 0;
    for (int j = 1; j <= 200; j++)
      if (ed >= st - 1) add = max(add, pre[ed][j] - pre[st - 1][j]);
    ans = max(ans, cnt + add);
  }
  return ans;
}
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    scanf("%d", &n);
    for (int i = 0; i <= 200; i++) pos[i] = 0, v[i].clear();
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), v[a[i]].push_back(i);
    printf("%d\n", solve());
  }
  return 0;
}
