#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 1], mx = 0;
    vector<int> pref[27];
    for (int i = 0; i <= n; i++) {
      for (int j = 1; j <= 26; j++) {
        pref[j].push_back(0);
      }
    }
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 26; j++) {
        if (j == a[i]) {
          pref[j][i] += pref[j][i - 1] + 1;
        } else {
          pref[j][i] += pref[j][i - 1];
        }
        mx = max(mx, pref[j][i]);
      }
    }
    for (int i = 1; i < n; i++) {
      int cnt = pref[a[i]][i], chk = pref[a[i]][n] - cnt, pos;
      pos = upper_bound(pref[a[i]].begin(), pref[a[i]].end(), chk) -
            pref[a[i]].begin() - 1;
      if (pos > i) {
        cnt *= 2;
        for (int j = 1; j <= 26; j++) {
          mx = max(mx, cnt + pref[j][pos] - pref[j][i]);
        }
      }
    }
    cout << mx << '\n';
  }
}
