#include <bits/stdc++.h>
using namespace std;
long long int b[27][2009];
long long int wow(long long int e, long long int l, long long int r) {
  if (r < l) return 0;
  return b[e][r] - b[e][l - 1];
}
int main() {
  long long int t;
  cin >> t;
  for (long long int i = 0; i <= 26; i++) b[i][0] = 0;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n + 1];
    for (long long int i = 1; i <= n; i++) {
      cin >> a[i];
      for (long long int j = 1; j <= 26; j++) {
        b[j][i] = 0;
        if (j == a[i]) b[j][i] = 1;
        b[j][i] += b[j][i - 1];
      }
    }
    long long int ans = 0;
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = i; j <= n; j++) {
        long long int m1 = 0, m2 = 0;
        for (long long int k = 1; k <= 26; k++) {
          m1 = max(m1, wow(k, i, j));
          m2 = max(m2, min(wow(k, 1, i - 1), wow(k, j + 1, n)));
        }
        ans = max(ans, m2 + m1 + m2);
      }
    }
    cout << ans << endl;
  }
}
