#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int>> pos(n);
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      pos[--x].push_back(i);
    }
    bool can = false;
    for (auto &x : pos) {
      if ((int)x.size() < 2) continue;
      if (x.back() - x.front() > 1) {
        can = true;
      }
    }
    cout << (can ? "YES" : "NO") << '\n';
  }
  return 0;
}
