#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, i, j, n, ara[5003], c[5003];
  cin >> t;
read:
  while (t--) {
    cin >> n;
    memset(c, 0, sizeof(c));
    for (i = 0; i < n; i++) {
      cin >> ara[i];
      c[ara[i]]++;
    }
    for (i = 0; i < n - 1; i++) {
      if (c[ara[i]] > 2) {
        cout << "YES" << endl;
        goto read;
      } else if (c[ara[i]] == 2 && ara[i] != ara[i + 1]) {
        if (i != 0 && (ara[i] == ara[i - 1])) continue;
        cout << "YES" << endl;
        goto read;
      }
    }
    cout << "NO" << endl;
  }
  return 0;
}
