#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long dp[27][2001];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      int temp;
      cin >> temp;
      for (int j = 1; j <= 26; j++) {
        if (j == temp)
          dp[j][i] = dp[j][i - 1] + 1;
        else
          dp[j][i] = dp[j][i - 1];
      }
    }
    long long ans = 0;
    for (long long l = 1; l <= n; l++) {
      for (long long r = l; r <= n; r++) {
        long long maxOcc = 0;
        long long a = 0;
        for (long long i = 1; i <= 26; i++) {
          maxOcc = max(maxOcc, dp[i][r] - dp[i][l - 1]);
          a = max(a, min(dp[i][l - 1], dp[i][n] - dp[i][r]) * 2);
        }
        ans = max(ans, maxOcc + a);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
