#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5 + 4;
const long long MOD = 998244353;
long long POW(long long base, long long exponent) {
  long long result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % MOD;
    exponent = exponent >> 1;
    base = (base * base) % MOD;
  }
  return result;
}
long long InvFac(long long x) { return POW(x, MOD - 2); }
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, mx1, mx2, mx = 0;
    cin >> n;
    int a[n], occ[n][26];
    memset(occ, 0, sizeof(occ));
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < n; j++) {
        if (a[j] == i + 1) {
          if (!j)
            occ[j][i] = 1;
          else
            occ[j][i] = occ[j - 1][i] + 1;
        } else if (j)
          occ[j][i] = occ[j - 1][i];
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        mx1 = 0, mx2 = 0;
        for (int k = 0; k < 26; k++) {
          if (i)
            mx1 = max(mx1, occ[j][k] - occ[i - 1][k]);
          else
            mx1 = max(mx1, occ[j][k]);
        }
        for (int k = 0; k < 26; k++) {
          if (i && j + 1 < n)
            mx2 = max(mx2, min(occ[i - 1][k], occ[n - 1][k] - occ[j][k]));
        }
        mx = max(mx, mx1 + 2 * mx2);
      }
    }
    cout << mx << '\n';
  }
  return 0;
}
