#include <bits/stdc++.h>
using namespace std;
string generateString(int a) {
  string s = "";
  for (int i = 0; i < a; i++) {
    char x = 'a' + i;
    s = s + x;
  }
  return s;
}
string wrapAround(string s, int b, int c) {
  int x = c - b;
  for (int i = 0; i < x; i++) {
    s += s[i % b];
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) {
      cin >> A[i];
    }
    vector<vector<int> > v;
    for (int i = 0; i < 26; i++) {
      vector<int> x(n + 1, 0);
      v.push_back(x);
    }
    for (int j = 0; j < n; j++) {
      v[A[j] - 1][j + 1]++;
    }
    for (int i = 0; i < 26; i++) {
      for (int j = 1; j < n + 1; j++) {
        v[i][j] += v[i][j - 1];
      }
    }
    vector<vector<int> > pos;
    pos.resize(26);
    for (int i = 0; i < n; i++) {
      pos[A[i] - 1].push_back(i);
    }
    int ans = 1;
    for (int i = 0; i < 26; i++) {
      int sz = pos[i].size();
      int lim = sz / 2;
      if (sz != 0) {
        for (int k = 0; k < lim; k++) {
          int st = pos[i][k];
          int en = pos[i][sz - k - 1];
          int temp = 0;
          for (int j = 0; j < 26; j++) {
            int x = v[j][en] - v[j][st + 1];
            temp = max(x, temp);
          }
          ans = max(ans, 2 * (k + 1) + temp);
        }
      }
    }
    cout << ans << "\n";
  }
}
