#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200010;
int sum[201][200001];
int a[Maxn], pre[Maxn], lst[Maxn], fst[Maxn], nxt[Maxn];
int main() {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      if (lst[a[i]]) {
        pre[i] = lst[a[i]];
        nxt[pre[i]] = i;
      } else
        fst[a[i]] = i;
      lst[a[i]] = i;
    }
    for (int i = 1; i <= 200; i++) {
      int cur = 1;
      for (int x = fst[i]; x; x = nxt[x]) {
        while (cur < x) sum[i][cur] = sum[i][cur - 1], cur++;
        sum[i][cur] = sum[i][cur - 1] + 1;
        cur++;
      }
      while (cur <= n) sum[i][cur] = sum[i][cur - 1], cur++;
    }
    int ans = 0;
    for (int i = 1; i <= 200; i++) {
      ans = max(ans, sum[i][n]);
      int l = fst[i], r = lst[i];
      for (int cnt = 2; l < r; l = nxt[l], r = pre[r], cnt += 2) {
        for (int k = 1; k <= 200; k++) {
          ans = max(ans, cnt + sum[k][r - 1] - sum[k][l]);
        }
      }
    }
    cout << ans << endl;
    for (int i = 1; i <= 200; i++) fst[i] = lst[i] = 0;
    for (int i = 1; i <= n; i++) pre[i] = nxt[i] = 0;
    for (int i = 1; i <= 200; i++)
      for (int j = 1; j <= n; j++) sum[i][j] = 0;
  }
  return 0;
}
