#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    int fre[n + 1][26];
    memset(fre, 0, sizeof(fre));
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      for (int j = 1; j <= 26; j++) {
        fre[i + 1][j] = fre[i][j];
      }
      fre[i + 1][arr[i]]++;
    }
    int ans = 1;
    for (int i = 1; i <= 26; i++) {
      for (int j = 1; j <= 26; j++) {
        ans = max(ans, fre[n][j]);
        if (i == j) continue;
        int low = 0, high = n - 1;
        int coun = 0;
        while (high >= low) {
          if (arr[low] == i) {
            while (arr[high] != arr[low]) {
              high--;
            }
            if (high == low) {
              coun++;
              ans = max(ans, coun + (fre[high][j] - fre[low][j]));
              break;
            } else {
              coun += 2;
              ans = max(ans, coun + (fre[high][j] - fre[low][j]));
              low++;
              high--;
            }
          } else
            low++;
        }
      }
    }
    cout << ans << endl;
  }
}
