#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int A[n];
    map<int, int> m_m;
    for (int i = 0; i < n; i++) {
      cin >> A[i];
      m_m[A[i]]++;
    }
    int t = 0;
    for (int i = 0; i < n - 1; i++) {
      if (m_m[A[i]] >= 2) {
        if (m_m[A[i]] >= 3) {
          t = 1;
          break;
        }
        if (A[i] != A[i + 1]) {
          t = 1;
          break;
        }
        m_m[A[i]]--;
      }
    }
    if (t == 1)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  return 0;
}
