#include <bits/stdc++.h>
using namespace std;
int tc, n, a[5005], pre[5005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  while (tc--) {
    cin >> n;
    memset(pre, -1, sizeof(pre));
    bool ada = false;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (pre[a[i]] == -1) {
        pre[a[i]] = i;
        continue;
      }
      if (pre[a[i]] + 2 <= i) {
        ada = true;
      }
    }
    cout << (ada ? "YES\n" : "NO\n");
  }
  return 0;
}
