#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int k;
    int a[n];
    for (k = 0; k < n; k++) scanf("%d", &a[k]);
    int p = n - 2;
    int i, j;
    for (i = 0; i < p; i++) {
      for (j = i + 2; j < n; j++) {
        if (a[i] == a[j]) {
          printf("YES\n");
          break;
        }
      }
      if (a[i] == a[j]) {
        break;
      }
    }
    if (a[i] == a[j]) continue;
    printf("NO\n");
  }
  return 0;
}
