#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], cnt[maxn][30];
int main() {
  int T;
  for (scanf("%d", &T); T; T--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      for (int j = 1; j <= 26; j++) cnt[i][j] = cnt[i - 1][j];
      cnt[i][a[i]]++;
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      for (int j = i + 1; j <= n + 1; j++) {
        int side = 0, mid = 0;
        for (int l = 1; l <= 26; l++) {
          mid = max(mid, cnt[j - 1][l] - cnt[i][l]);
          side =
              max(side, min(cnt[i][l] - cnt[0][l], cnt[n][l] - cnt[j - 1][l]));
        }
        ans = max(ans, side * 2 + mid);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
