#include <bits/stdc++.h>
using namespace std;
long long int ans;
vector<int> occ[200], v;
void solve() {
  long long int second = 0;
  for (int x : v) second += x;
  long long int l = 0, r = v.size() - 1;
  long long int x = 0;
  while (true) {
    x++;
    bool left = 0, right = 0;
    while (l <= r and !left) {
      if (!v[l])
        left = 1;
      else
        second--;
      l++;
    }
    while (l <= r and !right) {
      if (!v[r])
        right = 1;
      else
        second--;
      r--;
    }
    if (!left or !right) break;
    ans = max(ans, 2 * x + second);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n], i, j;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      --arr[i];
      occ[arr[i]].push_back(i);
    }
    ans = 0;
    for (i = 0; i < 200; i++) occ[i].push_back(n);
    for (i = 0; i < 200; i++) {
      if (occ[i].size() == 1) continue;
      for (j = 0; j < 200; j++) {
        if (i == j)
          ans = max((long long int)occ[i].size() - 1, ans);
        else {
          for (int a = 0, b = 0;
               a < occ[i].size() - 1 or b < occ[j].size() - 1;) {
            if (occ[i][a] < occ[j][b]) {
              v.push_back(0);
              ++a;
            } else {
              v.push_back(1);
              b++;
            }
          }
          solve();
          v.clear();
        }
      }
    }
    cout << ans << '\n';
    for (i = 0; i < 200; i++) occ[i].clear();
  }
  return 0;
}
