#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n, 0);
    unordered_map<int, int> vis;
    bool found = false;
    for (int l = 0; l < n; l++) {
      cin >> a[l];
      if (vis.find(a[l]) == vis.end()) {
        vis[a[l]] = l;
      } else if (l - vis[a[l]] > 1) {
        found = true;
      }
    }
    cout << (found == true ? "YES" : "NO") << "\n";
  }
  return 0;
}
