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