#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    bool ok = false;
    int n, a[5001];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n - 2; i++)
      for (int j = i + 2; j <= n; j++)
        if (a[i] == a[j]) ok = true;
    printf(ok ? "YES\n" : "NO\n");
  }
  return 0;
}
