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