#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x, y, z;
  for (cin >> t; t--;) {
    cin >> n >> x;
    unordered_set<int> ss;
    bool ok = false;
    for (int i = 1; i < n; ++i) {
      cin >> y;
      ok = ok || (ss.find(y) != ss.end());
      ss.insert(x);
      x = y;
    }
    cout << (ok ? "YES\n" : "NO\n");
  }
}
