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