#include <bits/stdc++.h>
using namespace std;
vector<int> pos[205];
int pre[205][200005];
int n;
void solve() {
  int ans = 0;
  cin >> n;
  for (int i = 1; i <= 200; i++) {
    pre[i][1] = 0;
    pos[i].clear();
  }
  for (int i = 1, a; i <= n; i++) {
    cin >> a;
    pos[a].push_back(i);
    for (int j = 1; j <= 200; j++) {
      pre[j][i] = pre[j][i - 1] + (a == j);
    }
  }
  for (int i = 1; i <= 200; i++) {
    int li = 0, ri = pos[i].size() - 1, nl = 0, nr = n + 1, cnt = 0;
    while (nl < nr) {
      int tmp = 0;
      for (int j = 1; j <= 200; j++) {
        tmp = max(tmp, pre[j][nr - 1] - pre[j][nl]);
      }
      ans = max(ans, tmp + cnt);
      if (li > ri) break;
      nl = pos[i][li++];
      nr = pos[i][ri--];
      cnt += 2;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
