#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n;
    cin >> n;
    long long int a[n];
    map<long long int, long long int> make_pair;
    long long int ok = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      make_pair[a[i]]++;
      if ((make_pair[a[i]] == 2 && a[i] != a[i - 1]) || make_pair[a[i]] == 3)
        ok = 1;
    }
    if (ok)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
