#include <bits/stdc++.h>
using namespace std;
const long long int Maxn = 2e3 + 5, N = 4e5 + 5, Mod = 1e9 + 7, Inf = 1e18,
                    Log = 22;
int t, n, a[Maxn], ans, ps[50][Maxn];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 26; j++) {
        ps[j][i] = 0;
      }
    }
    ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 26; j++) {
        ps[j][i] = ps[j][i - 1];
        ps[j][i] += (a[i] == j);
        ans = max(ans, ps[j][i]);
      }
    }
    for (int l = 1; l <= n; l++) {
      for (int r = l; r <= n; r++) {
        for (int i = 1; i <= 26; i++) {
          for (int j = 1; j <= 26; j++) {
            ans = max(ans, ps[i][r] - ps[i][l - 1] +
                               2 * min(ps[j][l - 1], ps[j][n] - ps[j][r]));
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
