#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  int amax = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int f = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 2; j < n; j++)
      if (a[j] == a[i]) {
        f = 1;
        break;
      }
  }
  if (f == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
