#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int i, j;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    int left[n][27];
    int right[n][27];
    memset(left, 0, sizeof(left));
    memset(right, 0, sizeof(right));
    left[0][a[0]] = 1;
    for (i = 1; i < n; i++) {
      for (j = 1; j <= 26; j++) {
        if (j == a[i]) {
          left[i][j] = left[i - 1][j] + 1;
        } else {
          left[i][j] = left[i - 1][j];
        }
      }
    }
    right[n - 1][a[n - 1]] = 1;
    for (i = n - 2; i >= 0; i--) {
      for (j = 1; j <= 26; j++) {
        if (j == a[i]) {
          right[i][j] = right[i + 1][j] + 1;
        } else {
          right[i][j] = right[i + 1][j];
        }
      }
    }
    int ans = 1;
    for (i = 0; i < n; i++) {
      for (j = n - 1; j >= 0; j--) {
        if (i >= j) {
          continue;
        }
        for (int k = 1; k <= 26; k++) {
          if (left[i][k] == right[j][k]) {
            for (int l = 1; l <= 26; l++) {
              ans = max(ans, 2 * left[i][k] + left[j - 1][l] - left[i][l]);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}
