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