#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int> > cnt(200, vector<int>(n + 1));
    vector<vector<int> > pos(200);
    for (int i = 0; i < int(n); ++i) {
      for (int j = 0; j < int(200); ++j) cnt[j][i + 1] = cnt[j][i];
      ++cnt[a[i] - 1][i + 1];
      pos[a[i] - 1].push_back(i);
    }
    int ans = 0;
    for (int i = 0; i < int(200); ++i) {
      ans = max(ans, int(pos[i].size()));
      for (int p = 0; p < int(int(pos[i].size()) / 2); ++p) {
        int l = pos[i][p] + 1, r = pos[i][int(pos[i].size()) - p - 1] - 1;
        for (int el = 0; el < int(200); ++el) {
          int sum = cnt[el][r + 1] - cnt[el][l];
          ans = max(ans, (p + 1) * 2 + sum);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
