#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
const int nax = 2123;
int N;
int f[nax][26];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  for (int qq = 1; qq <= tt; ++qq) {
    memset(f, 0, sizeof(f));
    cin >> N;
    for (int i = 0; i < N; ++i) {
      int a;
      cin >> a;
      ++f[i][a - 1];
    }
    for (int i = 1; i < N; ++i) {
      for (int j = 0; j < 26; ++j) {
        f[i][j] += f[i - 1][j];
      }
    }
    int max_len = 0;
    for (int i = 0; i < 26; ++i) uax(max_len, f[N - 1][i]);
    for (int l = 0; l < N - 2; ++l) {
      for (int r = l + 1; r < N - 1; ++r) {
        int lr = 0, mid = 0;
        for (int a = 0; a < 26; ++a) {
          uax(lr, min(f[l][a], f[N - 1][a] - f[r][a]) * 2);
          uax(mid, f[r][a] - f[l][a]);
        }
        uax(max_len, lr + mid);
      }
    }
    cout << max_len << '\n';
  }
}
