#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    map<int, int> seen;
    bool palindrome = false;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if (!seen[x]) seen[x] = i;
      if (seen[x] && seen[x] < i - 1) palindrome = true;
    }
    if (palindrome)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
