#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, a, flag = 1;
  cin >> t;
  while (t--) {
    flag = 1;
    cin >> n;
    vector<pair<int, int> > v(n + 1);
    for (i = 1; i < n + 1; i++) {
      cin >> a;
      v[a].first++;
      if (v[a].second == 0) v[a].second = i;
      if (flag) {
        if (v[a].first >= 2 && (i - v[a].second > 1)) {
          cout << "YES\n", flag = 0;
        }
      }
    }
    if (flag == 1) cout << "NO\n";
  }
}
