#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2001;
int a[MAXN];
vector<int> pd[27];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 26; i++) {
      pd[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      pd[a[i]].push_back(i);
    }
    int m = 0;
    for (int i = 1; i <= 26; i++) {
      int mm = 0;
      int r = pd[i].size(), l = r / 2;
      m = max(m, r);
      if (r < 2) continue;
      int rep[27] = {0};
      for (int j = pd[i][l - 1] + 1; j < pd[i][r - l]; j++) rep[a[j]]++;
      for (int j = 1; j <= 26; j++) mm = max(mm, rep[j]);
      m = max(m, l * 2 + mm);
      for (int j = l - 1; j > 0; j--) {
        for (int k = pd[i][j - 1] + 1; k < pd[i][j]; k++) rep[a[k]]++;
        for (int k = pd[i][r - j - 1] + 1; k < pd[i][r - j]; k++) rep[a[k]]++;
        for (int k = 1; k <= 26; k++) mm = max(mm, rep[k]);
        m = max(m, j * 2 + mm);
      }
    }
    cout << m << '\n';
  }
  return 0;
}
