#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, i, j, k, n, m, t;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int ar[n + 5];
    memset(ar, -1, sizeof(ar));
    int f = 0;
    for (i = 0; i < n; i++) {
      cin >> a;
      if (ar[a] == -1)
        ar[a] = i;
      else {
        if ((abs(i - ar[a]) - 1) >= 1) f = 1;
      }
    }
    if (f == 0)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
