#include <bits/stdc++.h>
using namespace std;
long long arr1[100][10000], arr[10000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, i, j, k, n, m, x, y, z, a, b, mx;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (i = 1; i < 27; i++) {
      x = 0;
      for (j = 0; j < n; j++) {
        if (arr[j] == i) {
          x++;
          arr1[i][j] = x;
        } else {
          arr1[i][j] = x;
        }
      }
    }
    mx = 1;
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (arr[j] == arr[i] &&
            (arr1[arr[i]][i]) == (arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1)) {
          x = arr1[arr[i]][i] + arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1;
          for (k = 1; k <= 26; k++) {
            y = arr1[k][j - 1] - arr1[k][i];
            z = x + y;
            mx = max(z, mx);
          }
        }
      }
    }
    cout << mx << endl;
  }
}
