#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-9;
const long long int INF = 1e18;
int dp[5005][5005];
int a[5005];
void solve() {
  int i, j, k, l, n, maxN = 1;
  cin >> n;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) dp[i][j] = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    dp[i][i] = 1;
  }
  for (i = 2; i <= n; i++) {
    for (j = 0; j + i - 1 < n; j++) {
      if (a[j] == a[j + i - 1])
        dp[j][j + i - 1] = 2 + dp[j + 1][j + i - 2];
      else
        dp[j][j + i - 1] = max(dp[j + 1][j + i - 1], dp[j][i + j - 2]);
      maxN = max(maxN, dp[j][j + i - 1]);
    }
  }
  if (maxN >= 3)
    cout << "YES\n";
  else
    cout << "NO\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int TC = 1, t = 0;
  cin >> TC;
  while (t++ < TC) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
