#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<vector<int>> dp(201, vector<int>(n, 0));
  dp[arr[0]][0]++;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < 201; j++) dp[j][i] = dp[j][i - 1];
    dp[arr[i]][i]++;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    int a = arr[i];
    int x = dp[a][i];
    int j, flag = 0;
    if ((dp[a][n - 1] - x) &&
        binary_search(dp[a].begin(), dp[a].end(), dp[a][n - 1] - x))
      j = upper_bound(dp[a].begin(), dp[a].end(), dp[a][n - 1] - x) -
          dp[a].begin();
    else
      flag = 1;
    if (j <= i) flag = 1;
    if (flag == 1) {
      res = max(res, x);
      continue;
    }
    int y = 0;
    for (int z = 1; z < 201; z++) y = max(y, dp[z][j - 1] - dp[z][i]);
    res = max(res, y + 2 * x);
  }
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
