#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int b[27][n + 1];
    for (int i = 0; i < 27; i++)
      for (int j = 0; j <= n; j++) b[i][j] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 26; j++) {
        if (a[i] == j)
          b[j][i + 1] = b[j][i] + 1;
        else
          b[j][i + 1] = b[j][i];
        ans = max(ans, b[j][i + 1]);
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        int p = 0, c;
        for (int k = 1; k < 27; k++) {
          if ((b[k][j + 1] - b[k][i]) > p) {
            c = k;
            p = b[k][j + 1] - b[k][i];
          }
        }
        for (int k = 1; k < 27; k++) {
          int d = b[k][i + 1], f = b[k][n] - b[k][j + 1];
          int e = min(f, d);
          if (k != c) ans = max(ans, p + 2 * e);
        }
      }
    }
    cout << ans << "\n";
  }
}
