#include <bits/stdc++.h>
using namespace std;
long long calc(long long l, long long r, vector<long long> v[]) {
  long long mx = 0, i;
  for (i = 1; i <= 200; i++) {
    long long g = v[i].size();
    if (g == 0) continue;
    auto itl = lower_bound(v[i].begin(), v[i].end(), l);
    auto itr = upper_bound(v[i].begin(), v[i].end(), r);
    mx = max(mx, (long long)(itr - itl));
  }
  return mx;
}
int main() {
  long long n, t, i, ans, x, j, l, r, g;
  ios_base::sync_with_stdio(0);
  ;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> v[201];
    for (i = 0; i < n; i++) {
      cin >> x;
      v[x].push_back(i);
    }
    long long mx = 0;
    ans = 0;
    for (i = 1; i <= 200; i++) {
      g = v[i].size();
      for (j = 0; j < g / 2; j++) {
        l = v[i][j];
        r = v[i][g - j - 1];
        if (l == r - 1) {
          continue;
        }
        long long tmp = j + 1;
        ans = max(ans, calc(l + 1, r - 1, v) + (tmp * 2));
      }
      ans = max(ans, g);
    }
    cout << ans << '\n';
  }
  return 0;
}
