#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
const long long INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
long long pow_mod(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - 48; isdigit(ch = getchar());
       res = (res << 1) + (res << 3) + ch - 48)
    ;
  flag && (res = -res);
}
long long a[maxn];
long long pre[maxn][30];
vector<long long> vec[30];
long long check_max(long long l, long long r) {
  long long t[30];
  for (long long i = 1; i <= 26; i++) {
    t[i] = pre[r - 1][i] - pre[l][i];
  }
  long long maxx = 0;
  for (long long i = 1; i <= 26; i++) {
    if (t[i] > maxx) {
      maxx = t[i];
    }
  }
  return maxx;
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    for (long long i = 1; i <= 26; i++) vec[i].clear();
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
      vec[a[i]].push_back(i);
      for (long long j = 1; j <= 26; j++) {
        pre[i][j] = pre[i - 1][j];
      }
      pre[i][a[i]]++;
    }
    long long ans = 0;
    for (long long i = 1; i <= 26; i++) {
      long long len = vec[i].size();
      if (!len) continue;
      ans = max(ans, len);
      long long t = len;
      long long l, r;
      if (len % 2 == 0) {
        l = len / 2, r = len / 2 + 1;
      } else {
        l = len / 2, r = len / 2 + 2;
        t--;
      }
      while (l >= 1 && r <= n) {
        long long zuo = vec[i][l - 1], you = vec[i][r - 1];
        long long yu = check_max(vec[i][l - 1], vec[i][r - 1]);
        ans = max(ans, t + yu);
        r++, l--;
        t -= 2;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
