#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC optimize(2)
const double eps = 1e-10;
const int maxn = 2e3 + 10;
const int mod = 998244353;
int sgn(double a) { return a < -eps ? -1 : a < eps ? 0 : 1; }
using namespace std;
int a[maxn];
int sum[maxn][27];
int vis1[27], vis2[27], vis3[27];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    memset(sum, 0, sizeof(sum));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 26; j++) sum[i][j] = sum[i - 1][j];
      sum[i][a[i]]++;
    }
    int Max = 0;
    for (int l = 1; l <= n; l++) {
      for (int r = l; r <= n; r++) {
        int cnt = 0, cmt = 0;
        for (int i = 1; i <= 26; i++) {
          cnt = (cnt > (sum[l - 1][i] < sum[n][i] - sum[r][i]
                            ? sum[l - 1][i]
                            : sum[n][i] - sum[r][i])
                     ? cnt
                     : (sum[l - 1][i] < sum[n][i] - sum[r][i]
                            ? sum[l - 1][i]
                            : sum[n][i] - sum[r][i]));
          cmt = (cmt > sum[r][i] - sum[l - 1][i] ? cmt
                                                 : sum[r][i] - sum[l - 1][i]);
        }
        Max = (Max > 2 * cnt + cmt ? Max : 2 * cnt + cmt);
      }
    }
    cout << Max << endl;
  }
  return 0;
}
