#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, i, j;
  cin >> n;
  vector<int> v(n);
  for (i = 0; i < n; i++) {
    cin >> j;
    v[i] = j;
  }
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (v[i - 1] == v[n - (j - 1) - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  if (dp[n][n] >= 3)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
