#include <bits/stdc++.h>
using namespace std;
const int MxN = 2 * 1e3 + 3;
template <typename T>
void Write(T x) {
  if (x > 9) Write(x / 10);
  putchar(x % 10 + 48);
}
bool visit[MxN];
map<string, bool> mp;
bitset<MxN> bt;
void solve() {
  long long ans = 0, a[MxN], dp[MxN][27], n, hi[27], mx, vv[27], x = 0;
  memset(vv, 0, sizeof(vv));
  memset(hi, 0, sizeof(hi));
  scanf("%lld", &n);
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for (int i = n - 1; ~i; --i) {
    hi[a[i]]++;
    x = max(x, hi[a[i]]);
    for (int j = 1; j <= 26; ++j) dp[i][j] = hi[j];
  }
  mx = 0;
  for (int i = 0; i < n; ++i) {
    vv[a[i]]++;
    long long v[27];
    memset(v, 0, sizeof(v));
    for (int j = i + 1; j < n; ++j) {
      v[a[j]]++;
      ans = max(ans, min(vv[a[i]], dp[j + 1][a[i]]) * 2 + v[a[j]]);
    }
  }
  cout << max(ans, x) << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  scanf("%d", &q);
  while (q--) {
    solve();
  }
}
