#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
vector<int> pos[205];
int a[maxn], pre[205][maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = (1); i <= (200); i++) pos[i].clear();
    for (int i = (1); i <= (n); i++) {
      cin >> a[i];
      pos[a[i]].push_back(i);
    }
    for (int i = (1); i <= (n); i++) {
      for (int j = (1); j <= (200); j++) pre[j][i] = pre[j][i - 1];
      pre[a[i]][i]++;
    }
    int ans = 0;
    for (int i = (1); i <= (200); i++) ans = max(ans, pre[i][n]);
    for (int i = (1); i <= (200); i++) {
      int l = 0, r = pos[i].size() - 1;
      while (l < r) {
        int num = 2 * (l + 1), mid = 0;
        for (int j = (1); j <= (200); j++) {
          mid = max(mid, pre[j][pos[i][r] - 1] - pre[j][pos[i][l]]);
        }
        ans = max(ans, num + mid);
        l++, r--;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
