#include <bits/stdc++.h>
using namespace std;
int a[200005], l[200005][205] = {0};
void solve() {
  int n;
  vector<int> pos[205];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      for (int j = 0; j <= 200; j++) {
        l[i][j] = l[i - 1][j];
      }
    } else {
      for (int j = 0; j <= 200; j++) l[i][j] = 0;
    }
    l[i][a[i]]++;
  }
  int ans = INT_MIN;
  for (int i = 1; i <= 200; i++) {
    ans = max(ans, l[n - 1][i]);
  }
  for (int i = 1; i <= 200; i++) {
    for (int j = 1; j <= pos[i].size() / 2; j++) {
      int mid = INT_MIN;
      for (int k = 1; k <= 200; k++) {
        mid =
            max(mid, l[pos[i][pos[i].size() - j] - 1][k] - l[pos[i][j - 1]][k]);
      }
      ans = max(ans, 2 * (j) + mid);
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  int t = 1;
  scanf("%lld", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
