package main
import "fmt"
func main() {
var t int
fmt.Scanf("%d", &t)
for k := 0; k < t; k++ {
var n int
fmt.Scanf("%d", &n)
a := make([]int, n)
for i := 0; i < n; i++ {
fmt.Scanf("%d", &a[i])
}
m := make(map[int]int)
for i := 0; i < n; i++ {
var j int
for j = i; j < n; j++ {
if a[j] == 0 {
break
}
}
if a[i] != 0 {
_, ok := m[j]
if !ok {
m[j] = i
}
}
}
if len(m) >= 2 {
fmt.Println(2)
} else {
fmt.Println(len(m))
}
}
}
cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCmZ1bmMgbWFpbigpIHsKCXZhciB0IGludAoJZm10LlNjYW5mKCIlZCIsICZ0KQoJZm9yIGsgOj0gMDsgayA8IHQ7IGsrKyB7CgkJdmFyIG4gaW50CgkJZm10LlNjYW5mKCIlZCIsICZuKQoJCWEgOj0gbWFrZShbXWludCwgbikKCQlmb3IgaSA6PSAwOyBpIDwgbjsgaSsrIHsKCQkJZm10LlNjYW5mKCIlZCIsICZhW2ldKQoJCX0KCQltIDo9IG1ha2UobWFwW2ludF1pbnQpCgkJZm9yIGkgOj0gMDsgaSA8IG47IGkrKyB7CgkJCXZhciBqIGludAoJCQlmb3IgaiA9IGk7IGogPCBuOyBqKysgewoJCQkJaWYgYVtqXSA9PSAwIHsKCgkJCQkJYnJlYWsKCQkJCX0KCQkJfQoJCQlpZiBhW2ldICE9IDAgewoJCQkJXywgb2sgOj0gbVtqXQoJCQkJaWYgIW9rIHsKCQkJCQltW2pdID0gaQoJCQkJfQoJCQl9CgkJfQoJCWlmIGxlbihtKSA+PSAyIHsKCQkJZm10LlByaW50bG4oMikKCQl9IGVsc2UgewoJCQlmbXQuUHJpbnRsbihsZW4obSkpCgkJfQoJfQp9Cg==