#include <bits/stdc++.h>
using namespace std;
string s;
int dp[5000][5000];
void trace(int l, int r) {
  if (l == r) {
    cout << s[l];
    return;
  }
  if (s[l] == s[r]) {
    cout << s[l];
    trace(l + 1, r - 1);
    cout << s[r];
    return;
  }
  if (dp[l][r] == dp[l + 1][r])
    trace(l + 1, r);
  else
    trace(l, r - 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    for (int i = 0; i < 5000; i++) {
      for (int j = 0; j < 5000; j++) dp[i][j] = 0;
    }
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int len = 1; len <= n; len++)
      for (int l = 0; l < n - len + 1; l++) {
        int r = l + len - 1;
        if (len == 1) {
          dp[l][r] = 1;
          continue;
        }
        if (len == 2) {
          dp[l][r] = 1 + (a[l] == a[r]);
          continue;
        }
        dp[l][r] = max(dp[l + 1][r], dp[l][r - 1]);
        if (a[l] == a[r]) dp[l][r] = max(dp[l][r], 2 + dp[l + 1][r - 1]);
      }
    if (dp[0][n - 1] >= 3)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
