#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    map<int, set<int>> m;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]].insert(i);
    }
    int flag = 0;
    for (auto i : m) {
      if (*(i.second.rbegin()) - *(i.second.begin()) > 1) {
        cout << "YES\n";
        flag = 1;
        break;
      }
    }
    if (!flag) cout << "NO\n";
  }
}
