#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 3;
int n, a, t, idx[N];
int main() {
  cin >> t;
  while (t--) {
    scanf("%d", &n);
    bool found = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      if (!idx[a])
        idx[a] = i + 1;
      else if (i + 1 - idx[a] >= 2) {
        found = 1;
      }
    }
    memset(idx, 0, sizeof idx);
    cout << (found ? "YES\n" : "NO\n");
  }
}
