#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long presum[27][2002];
vector<long long> vec[27];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, j, mx = 0, x, lastind;
    cin >> n;
    long long a[n + 1];
    for (i = 0; i <= 26; i++) vec[i].clear();
    for (i = 0; i <= 26; i++) {
      for (j = 0; j <= n; j++) presum[i][j] = 0;
    }
    for (i = 0; i < n; i++) {
      cin >> a[i];
      vec[a[i]].push_back(i);
      presum[a[i]][i] = 1;
    }
    for (i = 1; i <= 26; i++) {
      for (j = 1; j < n; j++) presum[i][j] += presum[i][j - 1];
    }
    for (i = 0; i < n; i++) {
      if (presum[a[i]][i] <= presum[a[i]][n - 1] / 2) {
        x = presum[a[i]][n - 1] - presum[a[i]][i];
        lastind = vec[a[i]][x] - 1;
        for (j = 1; j <= 26; j++) {
          mx = max(2 * presum[a[i]][i] + presum[j][lastind] - presum[j][i], mx);
        }
      } else
        mx = max(mx, presum[a[i]][i]);
    }
    cout << mx << "\n";
  }
}
