#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> v;
void mxpolindrome() {
  int l = 0, r = v.size() - 1;
  ;
  int mid = 0;
  for (auto i : v) mid += i;
  int per = 0;
  while (l <= r) {
    per++;
    bool l0 = 0, r0 = 0;
    while (!l0) {
      if (!v[l])
        l0 = 1;
      else
        mid--;
      l++;
    }
    while (!r0) {
      if (!v[r])
        r0 = 1;
      else
        mid--;
      r--;
    }
    if (!r0 || !l0 || r < l) break;
    ans = max(ans, 2 * per + mid);
  }
}
void solve() {
  int n;
  cin >> n;
  ans = 0;
  map<int, vector<int>> ind;
  for (int i = (int)(0); i < (int)(n); i++) {
    int a;
    cin >> a;
    ind[a].push_back(i);
  }
  for (int i = (int)(1); i < (int)(prev(ind.end())->first + 1); i++) {
    if (ind[i].size() == 0) continue;
    for (int j = (int)(1); j < (int)(prev(ind.end())->first + 1); j++) {
      if (j == i || ind[j].size() == 0) {
        ans = max(ans, (int)ind[i].size());
        continue;
      }
      for (int p = 0, l = 0; p < ind[i].size() || l < ind[j].size();) {
        if (l == ind[j].size()) {
          v.push_back(0), p++;
          continue;
        }
        if (p == ind[i].size()) {
          v.push_back(1), l++;
          continue;
        }
        if (ind[i][p] < ind[j][l])
          v.push_back(0), p++;
        else
          v.push_back(1), l++;
      }
      mxpolindrome();
      v.clear();
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt;
  cin >> tt;
  while (tt--) solve();
}
