#include <bits/stdc++.h>
using namespace std;
void fileio() {}
template <typename T>
void swap(T& a, T& b) {
  T temp = a;
  a = b;
  b = temp;
}
void solve() {
  long long int n;
  cin >> n;
  long long int* arr = new long long int[n];
  long long int count = 0;
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> arr[i];
  }
  unordered_map<long long int, long long int> m;
  long long int flag = 0;
  for (long long int i = 0; i < n; i++) {
    long long int a = arr[i];
    if (m.count(a) > 0) {
      if (i - m[a] > 1) {
        flag = 1;
        break;
      }
    } else {
      m[a] = i;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int32_t main() {
  fileio();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  for (long long int y = 1; y <= t; y++) {
    solve();
  }
  return 0;
}
