#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> mp;
  map<int, int>::iterator it;
  map<int, vector<int> > cnt;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cnt[a[i]].push_back(i);
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    if (it->second >= 3) {
      cout << "YES" << endl;
      return;
    }
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    if (it->second == 2) {
      if (cnt[it->first][1] - cnt[it->first][0] > 1) {
        cout << "YES" << endl;
        return;
      }
    }
  }
  cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
