#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const long long inf = 1e8;
const int N = 2e3 + 5;
const int M = 1e6 + 5;
const int mod = 998244353;
int n, m, k, t, T, len, op, z, x, y;
int sum[N][27], a[N];
int check(int x, int y) {
  int l = 1, r = n, res = 0, t1 = 0, t2 = 0;
  res = max(res, sum[r][y] - sum[l - 1][y]);
  while (l <= n) {
    while (l <= n && a[l] != x) l++;
    while (r >= 1 && a[r] != x) r--;
    if (l > r) break;
    t1++;
    l++;
    if (l > r) break;
    res = max(res, sum[r][y] - sum[l - 1][y] + 2 * min(t1, t2));
    t2++;
    r--;
    if (l > r) break;
    res = max(res, sum[r][y] - sum[l - 1][y] + 2 * min(t1, t2));
  }
  return res;
}
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) sum[i][j] = sum[i - 1][j];
    scanf("%d", &a[i]);
    sum[i][a[i]]++;
  }
  int ans = 0;
  for (int i = 1; i <= 26; i++) {
    for (int j = 1; j <= 26; j++) {
      if (i == j) continue;
      ans = max(ans, check(i, j));
    }
  }
  printf("%d\n", ans);
}
int main() {
  int o;
  scanf("%d", &o);
  while (o--) {
    solve();
  }
  return 0;
}
