#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long mod = 1e9 + 7;
const long long huge = 1e12;
long long fx, fy, ix, iy;
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
long long dis[N], a[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    long long b[203], c[203];
    long long dp[n + 3][202];
    vector<long long> ctf[202];
    for (long long i = 0; i <= n + 1; i++) {
      for (long long j = 0; j <= 200; j++) {
        dp[i][j] = 0;
      }
    }
    for (long long i = 0; i <= 200; i++) {
      b[i] = 0;
      c[i] = 0;
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= 200; j++) {
        dp[i][j] = dp[i - 1][j];
      }
      b[a[i]]++;
      dp[i][a[i]]++;
      ctf[a[i]].push_back(i);
    }
    for (long long i = n; i > 0; i--) {
      c[a[i]]++;
    }
    long long ans = 1;
    if (n == 2 && a[1] == a[2]) ans = 2;
    for (long long i = 2; i <= n - 1; i++) {
      for (long long j = 1; j <= 200; j++) {
        long long c = min(dp[i - 1][j], dp[n][j] - dp[i][j]);
        long long l, r;
        if (c == 0)
          l = 0, r = n + 1;
        else
          l = ctf[j][c - 1], r = ctf[j][b[j] - c];
        if (r == 0) r = n + 1;
        ans = max(ans, dp[r - 1][a[i]] - dp[l][a[i]] + 2 * c);
      }
    }
    cout << ans << '\n';
  }
}
