#include <bits/stdc++.h>
using namespace std;
long long t, n, a[2007], k1, k2, l, r, L, R, sz, res, mid;
map<long long, vector<long long> > mp;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    mp.clear();
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      mp[a[i]].push_back(i);
    }
    res = 0;
    for (auto p : mp) {
      k1 = p.first;
      sz = mp[k1].size();
      res = max(res, sz);
      for (auto f : mp) {
        if (f.first == k1) continue;
        k2 = f.first;
        mid = sz / 2;
        l = 0;
        r = mp[k2].size() - 1;
        for (int i = 1; i <= mid; i++) {
          L = mp[k1][i - 1];
          R = mp[k1][sz - i];
          while (l < mp[k2].size()) {
            if (mp[k2][l] < L)
              l++;
            else
              break;
          }
          while (r >= 0) {
            if (mp[k2][r] > R)
              r--;
            else
              break;
          }
          if (r < l || r == -1 || l == mp[k2].size()) break;
          res = max(r - l + 1 + 2 * i, res);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
