```go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
var t int
fmt.Fscan(in, &t)
for i := 0; i < t; i++ {
var n int
fmt.Fscan(in, &n)
a := make([]int, n)
counts := make([]int, n+2)
for j := 0; j < n; j++ {
fmt.Fscan(in, &a[j])
if a[j] <= n+1 {
counts[a[j]]++
}
}
m := 0
for counts[m] > 0 {
m++
}
target := m + 1
if counts[target] == 0 {
if n > m {
fmt.Fprintln(out, "Yes")
} else {
fmt.Fprintln(out, "No")
}
} else {
l, r := -1, -1
for j := 0; j < n; j++ {
if a[j] == target {
if l == -1 {
l = j
}
r = j
}
}
ok := true
removedCounts := make([]int, m)
for j := l; j <= r; j++ {
if a[j] < m {
removedCounts[a[j]]++
}
}
for j := 0; j < m; j++ {
if counts[j] == removedCounts[j] {
ok = false
break
}
}
if ok {
fmt.Fprintln(out, "Yes")
} else {
fmt.Fprintln(out, "No")
}
}
}
}
```