#include <bits/stdc++.h>
using namespace std;
const int M = 3000;
const int N = 30;
int t;
int n;
int a[M];
int sumfront[M][N];
int sumback[M][N];
int main() {
  cin >> t;
  while (t--) {
    memset(sumfront, 0, sizeof(sumfront));
    memset(sumback, 0, sizeof(sumback));
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= 26; ++j) {
        sumfront[i][j] = sumfront[i - 1][j];
      }
      sumfront[i][a[i]]++;
    }
    for (int i = n; i >= 1; --i) {
      for (int j = 1; j <= 26; ++j) {
        sumback[i][j] = sumback[i + 1][j];
      }
      sumback[i][a[i]]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = n; j >= i; --j) {
        int minx = 3000, maxx = 0, maxmid = 0;
        for (int k = 1; k <= 26; ++k) {
          minx = 3000;
          minx = min(sumfront[i - 1][k], sumback[j + 1][k]);
          maxx = max(maxx, minx);
          maxmid = max(maxmid, sumfront[j][k] - sumfront[i - 1][k]);
        }
        ans = max(ans, maxmid + 2 * maxx);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
