#include <bits/stdc++.h>
using namespace std;
int MAX_INT = numeric_limits<int>::max();
int MIN_INT = numeric_limits<int>::min();
long long MAX_LL = numeric_limits<long long>::max();
long long MIN_LL = numeric_limits<long long>::min();
long long MAX_ULL = numeric_limits<unsigned long long>::max();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int h = 0; h < t; h++) {
    int n;
    cin >> n;
    vector<int> arr(n);
    map<int, vector<int>> pos;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      pos[arr[i]].push_back(i);
    }
    bool ok = false;
    for (auto it : pos) {
      if (it.second.size() > 1 && it.second[0] + 1 < it.second.back()) {
        ok = true;
        cout << "YES" << '\n';
        break;
      }
    }
    if (!ok) cout << "NO" << '\n';
  }
}
