#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, b, dis, ans;
  cin >> t;
  vector<int> a;
  while (t--) {
    cin >> n;
    a.resize(n);
    vector<int> c(27, 0), d(27, 0);
    vector<vector<int>> b(n, vector<int>(27)), e(n, vector<int>(27));
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      c[a[i]]++;
      for (int j = 0; j < 27; j++) b[i][j] = c[j];
    }
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    for (int i = n - 1; i >= 0; i--) {
      d[a[i]]++;
      for (int j = 0; j < 27; j++) e[i][j] = d[j];
    }
    ans = 1;
    for (int i = 1; i < 27; i++) {
      if (c[i] < 2) continue;
      for (int k = 0; k < n; k++) {
        for (int h = n - 1; h > k; h--) {
          if (b[k][i] == e[h][i]) {
            for (int v = 1; v < 27; v++) {
              ans = max(ans, 2 * b[k][i] + b[h - 1][v] - b[k][v]);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}
