#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> arr(n + 1);
    vector<vector<int>> pos(201);
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
      pos[arr[i]].push_back(i);
    }
    vector<vector<int>> freq(201, vector<int>(n + 1));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 200; j++) {
        if (j == arr[i]) {
          freq[j][i] = freq[j][i - 1] + 1;
        } else {
          freq[j][i] = freq[j][i - 1];
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= 200; i++) {
      ans = max(ans, freq[i][n]);
      for (int j = 1; j <= 200; j++) {
        if (j == i) continue;
        int first = 0;
        int last = pos[j].size() - 1;
        while (first <= last) {
          int l = pos[j][first];
          int r = pos[j][last];
          int vall = freq[i][l - 1];
          int valr = freq[i][n] - freq[i][r];
          int val = 2 * min(vall, valr) + freq[j][r] - freq[j][l - 1];
          ans = max(ans, val);
          if (vall < valr) {
            first++;
          } else if (vall >= valr) {
            last--;
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
