#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    t--;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int index[n];
    for (int i = 0; i < n; i++) {
      index[i] = -1;
    }
    bool b = false;
    for (int i = 0; i < n; i++) {
      if (index[a[i] - 1] == -1) {
        index[a[i] - 1] = i;
      } else if (abs(index[a[i] - 1] - i) > 1) {
        b = true;
        break;
      } else {
      }
    }
    if (b) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
