#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, done = 0;
    cin >> n;
    vector<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[j] == a[i]) {
          done = 1;
        }
      }
    }
    if (done == 1) cout << "YES" << endl;
    if (done == 0) cout << "NO" << endl;
  }
  return 0;
}
