#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a > b) ? b : a; }
long long arr[100000];
long long n;
long long dp[5005][5005];
long long solve(long long i, long long j) {
  if (i >= n || j < 0) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  if (arr[i] == arr[j])
    return dp[i][j] = 1 + solve(i + 1, j - 1);
  else
    return dp[i][j] = max(solve(i + 1, j), solve(i, j - 1));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 0; i <= n; i++) {
      for (long long j = 0; j <= n; j++) dp[i][j] = -1;
    }
    for (long long i = 0; i <= n - 1; i++) {
      cin >> arr[i];
    }
    long long ans = solve(0, n - 1);
    if (ans >= 3)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
