#include <bits/stdc++.h>
using namespace std;
int arr[200002];
vector<int> v[201];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 200; i++) {
      v[i].clear();
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
      v[arr[i]].push_back(i);
      ans = max(ans, (int)v[arr[i]].size());
    }
    for (int i = 1; i <= 200; i++) {
      int c = v[i].size();
      int cc = 1;
      while (2 * cc <= c) {
        int l = v[i][cc - 1] + 1;
        int r = v[i][c - cc] - 1;
        int tem = 2 * cc;
        int mx = 0;
        if (l <= r) {
          for (int j = 1; j <= 200; j++) {
            if (v[j].size() == 0 || v[j].back() < l || v[j][0] > r) continue;
            int b = lower_bound(v[j].begin(), v[j].end(), l) - v[j].begin();
            int e = upper_bound(v[j].begin(), v[j].end(), r) - v[j].begin();
            mx = max(mx, e - b);
          }
          tem += mx;
        }
        ans = max(ans, tem);
        cc++;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
