#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc, n, i, j, p, k;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d", &n);
    vector<int> v[n + 5];
    for (i = 0; i < n; i++) {
      scanf("%d", &p);
      v[p].push_back(i);
    }
    k = 0;
    for (i = 1; i <= n; i++) {
      int b = 0;
      if (v[i].size() == 2) b = (v[i][1] - v[i][0]) > 1;
      if ((v[i].size() >= 3) || b) {
        k = 1;
        printf("YES");
        break;
      }
    }
    if (!k) printf("NO");
    printf("\n");
  }
  return 0;
}
