#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
const int K = 201;
int n, t, a[N], dp[K][N], f[K];
vector<int> id[K];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    int ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j < K; j++) dp[j][i] = 0, id[j].clear(), f[j] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 0; j < K; j++) {
        dp[j][i] = dp[j][i - 1];
        if (j == a[i]) id[j].push_back(i);
      }
      dp[a[i]][i]++;
    }
    memset(f, 0, sizeof f);
    for (int i = 1; i <= n; i++) {
      f[a[i]]++;
      ans = max(ans, f[a[i]]);
      int suf = (int)id[a[i]].size();
      int ID = suf - f[a[i]];
      ID = id[a[i]][ID];
      if (ID <= i) continue;
      int cur = f[a[i]] * 2;
      for (int j = 0; j < K; j++) {
        if (j == a[i]) continue;
        ans = max(ans, cur + dp[j][ID] - dp[j][i - 1]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
