#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> v(n);
    map<long long, vector<long long> > m;
    long long mx = 0, id;
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
      m[v[i]].push_back(i);
      mx = max(mx, (long long)m[v[i]].size());
    }
    long long res = mx;
    for (auto it : m) {
      long long sz = it.second.size(), ans = 0;
      long long cnt = 0, cnt2 = sz - 1, cntf = 0;
      long long i = it.second[cnt], j = it.second[cnt2];
      while (cnt < cnt2) {
        ans = 0;
        mx = 0;
        cntf += 2;
        map<long long, long long> temp;
        for (long long k = i + 1; k < j; k++) {
          if (v[k] == it.first) continue;
          temp[v[k]]++;
          mx = max(mx, temp[v[k]]);
        }
        ans = max(ans, mx) + cntf;
        cnt++, cnt2--;
        i = it.second[cnt], j = it.second[cnt2];
        res = max(res, ans);
      }
    }
    cout << res << '\n';
  }
  return 0;
}
