#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int freq[n][27];
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 26; j++) {
        freq[i][j] = (i - 1 >= 0) ? freq[i - 1][j] : 0;
      }
      freq[i][a[i]]++;
    }
    int res = 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int c = 1; c <= 26; c++) {
          int x1 = freq[i][c];
          int x2 = freq[n - 1][c] - freq[j - 1][c];
          if (x1 == x2) {
            res = max(res, x1 + x2);
            for (int c1 = 1; c1 <= 26; c1++) {
              int y = freq[j - 1][c1] - freq[i][c1];
              res = max(res, x1 + x2 + y);
            }
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
