#include <bits/stdc++.h>
using namespace std;
int a[10000];
void read(int &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int main() {
  int T, n;
  read(T);
  while (T--) {
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]);
    int ok = 0;
    for (int i = 1; i <= n; i++)
      for (int j = i + 2; j <= n; j++)
        if (a[i] == a[j]) {
          ok = 1;
          break;
        }
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
