#include <bits/stdc++.h>
using namespace std;
long long int dif(long long int a, long long int b) {
  return ((a / b) + (a % b != 0));
}
vector<long long int> v[5050];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, f = 0;
    cin >> n;
    for (long long int i = 1; i <= n; i++) {
      v[i].clear();
    }
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      v[a[i]].push_back(i);
    }
    for (long long int i = 1; i <= n; i++) {
      if (v[i].size() > 1) {
        if (v[i].size() > 2) f = 1;
        for (long long int j = 0; j < v[i].size() - 1; j++) {
          if (v[i][j + 1] - v[i][j] > 1) {
            f = 1;
          }
        }
      }
    }
    if (f) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
  return 0;
}
