#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, j, k;
    cin >> n;
    vector<vector<long long> > dp(26, vector<long long>(n + 1, 0));
    cin >> k;
    dp[k - 1][1] = 1;
    for (i = 1; i < n; i++) {
      cin >> k;
      for (j = 0; j < 26; j++) {
        dp[j][i + 1] = dp[j][i];
      }
      dp[k - 1][i + 1]++;
    }
    long long ans = 1;
    for (i = 0; i < 26; i++) {
      ans = max(ans, dp[i][n]);
    }
    for (i = 2; i <= n - 1; i++) {
      for (j = i; j <= n - 1; j++) {
        long long outerCnt = 0, innerCnt = 0;
        for (k = 0; k < 26; k++) {
          outerCnt =
              max(outerCnt,
                  2 * (min((dp[k][n] - dp[k][j]), (dp[k][i - 1] - dp[k][0]))));
          innerCnt = max(innerCnt, dp[k][j] - dp[k][i - 1]);
        }
        ans = max(ans, innerCnt + outerCnt);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
