#include <bits/stdc++.h>
using namespace std;
bool test(const vector<long long>& a) {
  set<long long> seen;
  for (long long i = 1; i < a.size(); i++) {
    if (seen.count(a[i])) return true;
    seen.insert(a[i - 1]);
  }
  return false;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  for (long long nr = 0; nr < t; nr++) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    cout << (test(a) ? "YES" : "NO") << '\n';
  }
}
