#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, inf = 0x3f3f3f3f, mod = 1000000007;
void read() {}
template <typename T, typename... T2>
inline void read(T &x, T2 &...oth) {
  x = 0;
  int ch = getchar(), f = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  if (f) x = -x;
  read(oth...);
}
int a[maxn], sum[206][maxn];
signed main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int lim = 0;
    map<int, int> mp[206], mp2[206];
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      lim = max(lim, a[i]);
      for (int j = 1; j <= 200; j++) sum[j][i] = sum[j][i - 1];
      sum[a[i]][i]++;
      mp[a[i]][sum[a[i]][i]] = i;
    }
    int ans = 0;
    for (int i = 1; i <= lim; i++) {
      for (int num = 1; num * 2 <= sum[i][n]; num++) {
        int l = mp[i][num] + 1, r = mp[i][sum[i][n] - num + 1] - 1;
        for (int j = 1; j <= lim; j++)
          ans = max(ans, 2 * num + sum[j][r] - sum[j][l - 1]);
      }
    }
    cout << max(1, ans) << endl;
  }
  return 0;
}
