#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 != 0) {
      ans = (ans * a) % 1000000007;
    }
    a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
    b >>= 1;
  }
  return ans;
}
void sieve(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p]) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++) {
    if (prime[p]) cout << p << " ";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int test = 1;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    map<int, vector<int>> m;
    for (int i = 0; i < n; i++) {
      int z;
      cin >> z;
      m[z].push_back(i);
    }
    int ans = 0;
    for (auto i : m) {
      int le = i.second.size();
      ans = max(ans, le);
      for (auto j : m) {
        if (i.first == j.first) {
          continue;
        }
        vector<int> v1, v2, v;
        v1 = i.second;
        v2 = j.second;
        int l1 = 0, l2 = 0;
        if (v1[v1.size() - 1] < v2[0]) continue;
        if (v1[0] > v2[v2.size() - 1]) continue;
        while (l1 < v1.size() && l2 < v2.size()) {
          if (v1[l1] < v2[l2]) {
            v.push_back(-1);
            l1++;
          } else {
            v.push_back(1);
            l2++;
          }
        }
        while (l1 < v1.size()) {
          v.push_back(-1);
          l1++;
        }
        int ha = 0;
        int p = 0, q = v.size() - 1;
        int cnt1 = 0, cnt2 = l2;
        while (p < q) {
          if (v[p] == 1) {
            cnt2--;
            p++;
            continue;
          }
          if (v[q] == 1) {
            cnt2--;
            q--;
            continue;
          }
          cnt1 += 2;
          ans = max(ans, cnt1 + cnt2);
          p++;
          q--;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
