#include <bits/stdc++.h>
using namespace std;
vector<int> cnt[206];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, i, x, j, y, a[200005], l, r, ans = 0;
    cin >> n;
    for (i = 1; i <= 200; i++) {
      cnt[i].clear();
      cnt[i].resize(n + 5);
    }
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    cnt[a[0]][0] = 1;
    for (i = 1; i < n; i++) {
      for (j = 1; j <= 200; j++) {
        if (a[i] == j) {
          cnt[j][i] = 1 + cnt[j][i - 1];
        } else {
          cnt[j][i] = cnt[j][i - 1];
        }
      }
    }
    for (i = 1; i <= 200; i++) {
      ans = max(ans, cnt[i][n - 1]);
    }
    for (i = 1; i <= 200; i++) {
      x = cnt[i][n - 1];
      y = 0;
      l = 0;
      r = n - 1;
      while (l <= r) {
        y++;
        while (cnt[i][l] != y && l < n) {
          l++;
        }
        while (cnt[i][r] != x - y && r > 0) {
          r--;
        }
        if (l >= r) {
          break;
        }
        int mm = 0;
        for (j = 1; j <= 200; j++) {
          mm = max(mm, cnt[j][r] - cnt[j][l]);
        }
        ans = max(ans, 2 * y + mm);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
