#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
long long a[N], l[N][30], r[N][30];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i <= n + 1; i++)
    for (long long j = 1; j <= 26; j++) {
      l[i][j] = 0;
      r[i][j] = 0;
    }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 26; j++) {
      l[i][j] = l[i - 1][j];
    }
    l[i][a[i]]++;
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j <= 26; j++) {
      r[i][j] = r[i + 1][j];
    }
    r[i][a[i]]++;
  }
  long long ans = 0;
  for (long long i = 0; i <= n; i++)
    for (long long j = i + 1; j <= n + 1; j++)
      for (long long k = 1; k <= 26; k++)
        for (long long m = 1; m <= 26; m++) {
          ans = max(ans, min(l[i][k], r[j][k]) * 2 + l[j - 1][m] - l[i][m]);
        }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) solve();
}
