#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int T;
  std::cin >> T;
  while (T--) {
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for (int i = 0; i < N; i++) std::cin >> a[i];
    std::vector<std::vector<int>> pre(200 + 1, std::vector<int>(N, 0)),
        pre_inv(200 + 1, std::vector<int>(1, 0));
    pre[a[0]][0] = 1;
    for (int i = 1; i < N; i++) {
      for (int j = 1; j <= 200; j++) pre[j][i] = pre[j][i - 1];
      pre[a[i]][i]++;
    }
    for (int i = 0; i < N; i++) pre_inv[a[i]].push_back(i);
    int best = 0;
    for (int i = 1; i <= 200; i++) best = std::max(best, pre[i][N - 1]);
    for (int i = 0; i < N; i++) {
      int opp = pre_inv[a[i]][pre[a[i]][N - 1] - pre[a[i]][i] + 1];
      if (opp <= i) continue;
      int outer = 2 * pre[a[i]][i];
      int inner = 0;
      for (int j = 1; j <= 200; j++)
        inner = std::max(inner, pre[j][opp - 1] - pre[j][i]);
      best = std::max(best, outer + inner);
    }
    std::cout << best << "\n";
  }
}
