#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn];
int vis[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    memset(vis, 0, sizeof(vis));
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      if (vis[a[i]] && i - vis[a[i]] != 1) {
        flag = true;
        break;
      }
      if (!vis[a[i]]) vis[a[i]] = i;
    }
    if (flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
