#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  unordered_map<int, int> c;
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--, c[a[i]]++;
  if (n == 1) {
    cout << 1 << '\n';
    return;
  }
  if (n == 2) {
    if (a[0] == a[1])
      cout << 2 << '\n';
    else
      cout << 1 << '\n';
    return;
  }
  int maxi = -1;
  for (auto i = c.begin(); i != c.end(); i++) maxi = max(maxi, (*i).second);
  int cnt[26][n];
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (!i) {
        cnt[a[i]][i]++;
        break;
      }
      if (a[i] == j)
        cnt[a[i]][i] = cnt[a[i]][i - 1] + 1;
      else
        cnt[j][i] = cnt[j][i - 1];
    }
  }
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 2; j < n; j++) {
      int maxi2 = -1;
      for (int k = 0; k < 26; k++)
        maxi2 = max(maxi2, cnt[k][j - 1] - cnt[k][i]);
      for (int k = 0; k < 26; k++) {
        int t1 = cnt[k][i], t2 = cnt[k][n - 1] - cnt[k][j - 1];
        if (t1 == t2)
          maxi = max(maxi, maxi2 + cnt[k][i] + cnt[k][n - 1] - cnt[k][j - 1]);
      }
    }
  }
  cout << maxi << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
