#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int max = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n - 2; i++) {
      if (max == 0)
        for (int j = i + 2; j < n; j++) {
          if (a[i] == a[j]) {
            cout << "YES"
                 << "\n";
            max = 1;
            break;
          }
        }
    }
    if (max == 0) cout << "NO" << endl;
  }
  return 0;
}
