#include <bits/stdc++.h>
using namespace std;
const long long DIM = 2e5 + 7;
long long n, used[27][DIM], a[DIM], tests;
int in;
int main() {
  in = scanf("%lld", &tests);
  for (long long test = 1; test <= tests; test++) {
    in = scanf("%lld", &n);
    long long result = 0;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= 26; j++) {
        used[j][i] = used[j][i - 1];
      }
      in = scanf("%lld", &a[i]);
      used[a[i]][i]++;
    }
    for (long long i = 1; i <= 26; i++) result = max(result, used[i][n]);
    long long cntin = 0, cntout = 0;
    for (long long l = 1; l <= n; l++) {
      for (long long r = l; r <= n; r++) {
        cntin = 0;
        cntout = 0;
        for (long long x = 1; x <= 26; x++) {
          cntin = max(cntin, used[x][r] - used[x][l - 1]);
        }
        for (long long x = 1; x <= 26; x++)
          cntout =
              max(cntout, min(used[x][l - 1], used[x][n] - used[x][r]) * 2);
        result = max(result, cntout + cntin);
      }
    }
    printf("%lld\n", result);
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= 26; j++) {
        used[j][i] = 0;
      }
    }
  }
  return 0;
}
