#include <bits/stdc++.h>
using namespace std;
int arr[2005], flag[2005][30];
signed main() {
  int t;
  cin >> t;
  while (t--) {
    int n, arr[2005], num = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 26; j++) {
        flag[i][j] = flag[i - 1][j];
      }
      flag[i][arr[i]]++;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        int ass = 0, ans = 0;
        for (int m = 1; m <= 26; m++)
          ass = max(ass, min(flag[i][m], flag[n][m] - flag[j - 1][m]));
        for (int m = 1; m <= 26; m++)
          ans = max(ans, flag[j - 1][m] - flag[i][m]);
        if (num < ass * 2 + ans) num = ass * 2 + ans;
      }
    }
    cout << num << endl;
    memset(flag, 0, sizeof flag);
    memset(arr, 0, sizeof arr);
  }
  return 0;
}
