#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> v;
int lbd(int idx, int no) {
  return lower_bound(v[idx].begin(), v[idx].end(), no) - v[idx].begin() - 1;
}
int ubd(int idx, int no) {
  return upper_bound(v[idx].begin(), v[idx].end(), no) - v[idx].begin();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, tmp;
  cin >> t;
  while (t--) {
    int ans = 1;
    v = vector<vector<int>>(27);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> tmp;
      v[tmp].push_back(i);
    }
    for (int i = 1; i <= 26; ++i) {
      if (v[i].size() <= 1) continue;
      int s = 0, e = v[i].size() - 1, cnt = 1;
      while (s < e) {
        for (int j = 1; j <= 26; ++j)
          ans = max(ans, lbd(j, v[i][e]) - ubd(j, v[i][s]) + 1 + 2 * cnt);
        ++s;
        --e;
        ++cnt;
      }
    }
    cout << ans << '\n';
  }
}
