#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int a[5001];
bool coutNO;
vector<int> check[5001];
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int ct = 1; ct <= t; ct++) {
    cin >> n;
    coutNO = true;
    for (int i = 1; i <= n; i++) check[i].clear();
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      check[a[i]].push_back(i);
      if (check[a[i]].size() >= 3) coutNO = false;
    }
    if (!coutNO) {
      cout << "YES" << '\n';
      continue;
    }
    for (int i = 1; i <= n; i++)
      if (check[i].size() == 2) {
        if (check[i][0] + 1 != check[i][1]) {
          coutNO = false;
          break;
        }
      }
    if (coutNO)
      cout << "NO" << '\n';
    else
      cout << "YES" << '\n';
  }
  return 0;
}
