#include <bits/stdc++.h>
using namespace std;
int a[5005];
int used[5005];
int main() {
  int t, n, i, j;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n;
    memset(used, 0, sizeof(used));
    bool lamp = false;
    for (j = 1; j <= n; j++) {
      cin >> a[j];
      if (!used[a[j]])
        used[a[j]] = j;
      else if (used[a[j]] + 1 != j)
        lamp = true;
    }
    if (lamp)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
