#include <bits/stdc++.h>
using namespace std;
struct tree {
  int f[205];
};
void build(struct tree t[], long long n) {
  for (long long i = n - 1; i > 0; i--) {
    for (long long j = 0; j < 205; j++) {
      t[i].f[j] = t[i << 1].f[j] + t[i << 1 | 1].f[j];
    }
  }
}
int query(struct tree t[], long long n, long long l, long long r) {
  int res[205];
  for (long long i = 0; i < 205; i++) res[i] = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      for (long long j = 0; j < 205; j++) res[j] += t[l].f[j];
      l++;
    }
    if (r & 1) {
      --r;
      for (long long j = 0; j < 205; j++) res[j] += t[r].f[j];
    }
  }
  int ans = 0;
  for (long long j = 0; j < 205; j++) {
    ans = max(ans, res[j]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int a[n];
    struct tree t[2 * n];
    int f[205] = {0};
    int ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      f[a[i]]++;
      ans = max(ans, f[a[i]]);
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 205; j++) {
        t[n + i].f[j] = 0;
      }
      t[n + i].f[a[i]]++;
    }
    build(t, n);
    for (int i = 0; i < 205; i++) {
      if (f[i] <= 1) continue;
      int x = f[i] / 2, cnt = 0;
      int l = 0, r = n - 1;
      vector<long long> L, R, W;
      while (l < n) {
        if (a[l] == i) cnt++;
        l++;
        if (a[l - 1] == i) {
          L.push_back(l);
          W.push_back(cnt);
        }
        if (cnt == x) break;
      }
      while (r >= 0) {
        if (a[r] == i) cnt--;
        r--;
        if (a[r + 1] == i) R.push_back(r);
        if (cnt == 0) break;
      }
      int tmp = 0, mx = 0;
      for (int j = 0; j < L.size(); j++) {
        mx = query(t, n, L[j], R[j] + 1);
        tmp = max(tmp, (int)(2 * W[j] + mx));
      }
      ans = max(ans, tmp);
    }
    cout << ans << '\n';
  }
}
