#include <bits/stdc++.h>
using namespace std;
void IOS() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int32_t main() {
  long long int test;
  cin >> test;
  for (long long int u = 0; u < test; u++) {
    long long int n;
    cin >> n;
    long long int a[n + 1];
    long long int coun[26];
    for (long long int i = 0; i < 26; i++) {
      coun[i] = 0;
    }
    for (long long int i = 1; i <= n; i++) {
      cin >> a[i];
      coun[a[i] - 1]++;
    }
    long long int dp1[27][n + 1], dp2[27][n + 1];
    for (long long int i = 0; i < 27; i++) {
      for (long long int j = 0; j <= n + 1; j++) {
        dp1[i][j] = 0;
        dp2[i][j] = 0;
      }
    }
    vector<long long int> v1[27];
    vector<long long int> v2[27];
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = 1; j < 27; j++) {
        if (j == a[i]) {
          dp1[j][i] = dp1[j][i - 1] + 1;
          v1[j].push_back(i);
        } else {
          dp1[j][i] = dp1[j][i - 1];
        }
      }
    }
    for (long long int i = n, k = 1; i > 0; i--, k++) {
      for (long long int j = 1; j < 27; j++) {
        if (j == a[i]) {
          dp2[j][k] = dp2[j][k - 1] + 1;
          v2[j].push_back(i);
        } else {
          dp2[j][k] = dp2[j][k - 1];
        }
      }
    }
    long long int maxx = 0;
    for (long long int i = 1; i < 27; i++) {
      long long int lef, rig, in = 0;
      while (in < v1[i].size()) {
        lef = v1[i][in];
        rig = v2[i][in];
        if (lef >= rig) break;
        for (long long int j = 1; j < 27; j++) {
          if (2 * (in + 1) + (dp1[j][rig - 1] - dp1[j][lef]) > maxx) {
            maxx = 2 * (in + 1) + (dp1[j][rig - 1] - dp1[j][lef]);
          }
        }
        in++;
      }
    }
    long long int maxx2 = *max_element(coun, coun + 26);
    cout << max(maxx, maxx2) << endl;
  }
}
