#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    int a[5001];
    for (int i = 0; i <= n; i++) {
      a[i] = -1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (a[v[i]] == -1) {
        a[v[i]] = i;
      } else {
        int x = abs(a[v[i]] - i);
        if (x > 1) {
          ans = 1;
          break;
        }
      }
    }
    if (ans == 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
