#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    bool check = false;
    for (i = 0; i < n; i++) {
      for (j = i + 2; j < n; j++) {
        if (a[i] == a[j]) check = true;
      }
    }
    if (check)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
