#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &it : v) cin >> it;
    vector<vector<int> > pre(26, vector<int>(n + 1));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 26; j++) pre[j][i + 1] = pre[j][i];
      pre[v[i] - 1][i + 1]++;
    }
    int ans = 0;
    for (int i = 0; i < 26; i++) ans = max(ans, pre[i][n - 1]);
    for (int i = 0; i < n; i++) {
      for (int k = i; k < n; k++) {
        int sec = 0, fi_th = 0;
        for (int j = 0; j < 26; j++) {
          sec = max(sec, pre[j][k + 1] - pre[j][i]);
          fi_th = max(fi_th, min((pre[j][i]), (pre[j][n] - pre[j][k + 1])) * 2);
        }
        ans = max(ans, sec + fi_th);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
