#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long int max(long long int a, long long int b) { return (a > b) ? a : b; }
vector<long long int> v;
long long int ans;
void solve() {
  long long int noOfOnes = 0;
  long long int noOfZeroes = 0;
  for (long long int it : v) {
    noOfOnes += it;
  }
  ans = max(ans, noOfOnes);
  long long int left = 0;
  long long int right = v.size() - 1;
  long long int noOfX = 0;
  while (1) {
    noOfX++;
    long long int bl, br;
    bl = br = 0;
    while (left <= right && !bl) {
      if (v[left] == 1) {
        left++;
        noOfOnes--;
      } else {
        left++;
        bl = 1;
      }
    }
    while (left <= right && !br) {
      if (v[right] == 1) {
        right--;
        noOfOnes--;
      } else {
        right--;
        br = 1;
      }
    }
    if (!bl || !br) {
      break;
    }
    ans = max((2 * noOfX + noOfOnes), ans);
  }
}
int32_t main() {
  fastIO();
  long long int t;
  cin >> t;
  while (t--) {
    vector<long long int> occ[200];
    long long int n;
    cin >> n;
    long long int data;
    for (long long int i = 0; i < n; i++) {
      cin >> data;
      occ[data - 1].push_back(i);
    }
    for (long long int i = 0; i < 200; i++) {
      occ[i].push_back(n);
    }
    ans = 0;
    for (long long int a = 0; a < 200; a++) {
      if (occ[a].size() == 1) continue;
      for (long long int b = 0; b < 200; b++) {
        v.clear();
        if (a == b) {
          ans = max(occ[a].size() - 1, ans);
          continue;
        }
        for (long long int i = 0, j = 0;
             i < occ[a].size() - 1 || j < occ[b].size() - 1;) {
          if (occ[a][i] < occ[b][j]) {
            v.push_back(0);
            i++;
          } else {
            v.push_back(1);
            j++;
          }
        }
        solve();
      }
    }
    cout << ans << endl;
  }
  return 0;
}
