#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n, res = -3;
    cin >> n;
    int b[27][n + 1];
    for (int i = 0; i < 27; ++i) {
      for (int j = 0; j < n + 1; ++j) b[i][j] = 0;
    }
    for (int i = 1; i < n + 1; ++i) {
      int k;
      cin >> k;
      b[k][i]++;
    }
    for (int i = 1; i < 27; ++i) {
      int sum = 0;
      for (int j = 0; j < n + 1; ++j) {
        sum += b[i][j];
        b[i][j] = sum;
      }
    }
    for (int r = 1; r < n + 1; ++r) {
      for (int s = r; s < n + 1; ++s) {
        int count = 0, count1 = 0;
        for (int i = 1; i < 27; ++i) {
          if (min(b[i][r - 1], b[i][n] - b[i][s]) > count) {
            count = min(b[i][r - 1], b[i][n] - b[i][s]);
          }
          if (b[i][s] - b[i][r - 1] > count1) count1 = b[i][s] - b[i][r - 1];
        }
        if (res < 2 * count + count1) {
          res = 2 * count + count1;
        }
      }
    }
    cout << res << "\n";
  }
}
