#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    int freq[n][201];
    for (int i = 0; i <= 200; i++) freq[0][i] = 0;
    for (int i = 0; i < n; i++) cin >> arr[i];
    freq[0][arr[0]]++;
    for (int i = 1; i < n; i++) {
      for (int j = 1; j <= 200; j++) {
        freq[i][j] = freq[i - 1][j];
      }
      freq[i][arr[i]]++;
    }
    map<pair<int, int>, int> mp;
    vector<int> f(201);
    for (int i = n - 1; i >= 0; i--) {
      f[arr[i]]++;
      int a = arr[i], b = f[arr[i]];
      mp[{a, b}] = i;
    }
    int ans = 1;
    for (int i = 0; i < n; i++) {
      int cur = arr[i];
      int reqfreq = freq[i][cur];
      if (mp.find({cur, reqfreq}) == mp.end()) continue;
      int index = mp[{cur, reqfreq}];
      if (index <= i) continue;
      int res = 0;
      for (int j = 1; j <= 200; j++) {
        res = max(res, freq[index - 1][j] - freq[i][j]);
      }
      ans = max(ans, 2 * reqfreq + res);
    }
    cout << ans << "\n";
  }
}
