#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline bool chmax(int& a, int b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int B = 210;
int q, n, e, i, j, ans, res, l, r, val, x, mid;
void solve() {
  cin >> n;
  vector<vector<int>> sum(n + 1, vector<int>(B, 0));
  for (i = 0; i < n; i++) {
    for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];
    cin >> e;
    sum[i + 1][e]++;
  }
  ans = 0;
  for (x = 0; x < B; x++) {
    res = 0;
    l = 0;
    r = n;
    val = 0;
    while (l < r) {
      mid = 0;
      while (l < n and sum[l][x] < val) l++;
      while (0 < r and sum[n][x] - sum[r][x] < val) r--;
      if (r <= l) break;
      for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);
      chmax(res, mid + sum[l][x] + sum[l][x]);
      val++;
    }
    chmax(ans, res);
  }
  cout << ans << '\n';
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> q;
  while (q--) {
    cin >> n;
    vector<vector<int>> sum(n + 1, vector<int>(B, 0));
    for (i = 0; i < n; i++) {
      for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];
      cin >> e;
      sum[i + 1][e]++;
    }
    ans = 0;
    for (x = 0; x < B; x++) {
      res = 0;
      l = 0;
      r = n;
      val = 0;
      while (l < r) {
        mid = 0;
        while (l < n and sum[l][x] < val) l++;
        while (0 < r and sum[n][x] - sum[r][x] < val) r--;
        if (r < l) break;
        for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);
        chmax(res, mid + sum[l][x] + sum[l][x]);
        val++;
      }
      chmax(ans, res);
    }
    cout << ans << '\n';
  }
  return 0;
}
