#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 100;
int n, a[N];
bool check() {
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= 1; j--) {
      if (a[i] == a[j] && i + 1 < j) return true;
    }
  }
  return false;
}
int main() {
  int w;
  cin >> w;
  while (w--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    if (check())
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
