For a collection of integers $$$S$$$, define $$$\operatorname{mex}(S)$$$ as the smallest non-negative integer that does not appear in $$$S$$$.NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the universe by snapping his fingers several times.The universe can be represented as a 1-indexed array $$$a$$$ of length $$$n$$$. When NIT snaps his fingers, he does the following operation on the array:  He selects positive integers $$$l$$$ and $$$r$$$ such that $$$1\le l\le r\le n$$$. Let $$$w=\operatorname{mex}(\{a_l,a_{l+1},\dots,a_r\})$$$. Then, for all $$$l\le i\le r$$$, set $$$a_i$$$ to $$$w$$$. We say the universe is destroyed if and only if for all $$$1\le i\le n$$$, $$$a_i=0$$$ holds.Find the minimum number of times NIT needs to snap his fingers to destroy the universe. That is, find the minimum number of operations NIT needs to perform to make all elements in the array equal to $$$0$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$0\le a_i\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, print one integer — the answer to the problem.

NoteIn the first test case, we do $$$0$$$ operations and all elements in the array are already equal to $$$0$$$.In the second test case, one optimal way is doing the operation with $$$l=2$$$, $$$r=5$$$.In the third test case, one optimal way is doing the operation twice, respectively with $$$l=4$$$, $$$r=4$$$ and $$$l=2$$$, $$$r=6$$$.In the fourth test case, one optimal way is doing the operation with $$$l=1$$$, $$$r=1$$$.

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		non_zero := false
		zero_after_non_zero := false
		more := false
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if zero_after_non_zero && a[i] != 0 {
				more = true
			}

			if non_zero && a[i] == 0 {
				zero_after_non_zero = true
			}
			if a[i] != 0 {
				non_zero = true
			}
		}
		if more {
			fmt.Println(2)
		} else {
			if non_zero {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}

	}
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		started := false
		if a[0] != 0 {
			started = true
		}
		ans := 0
		for i := 1; i < n; i++ {
			if started {
				if a[i] == 0 {
					ans++
					started = false
				}
			} else {
				if a[i-1] == 0 && a[i] != 0 {
					started = true
				}
			}
		}
		if a[n-1] != 0 && started {
			ans++
		}
		if ans > 2 {
			fmt.Println(2)
		} else {
			fmt.Println(ans)
		}
	}
}

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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		var ans int
		var f bool
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			if v == 0 {
				f = false
			} else {
				if !f {
					ans++
					f = true
				}
			}
		}

		if ans > 2 {
			ans = 2
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var qq int
//	fmt.Scan(&qq)
	fmt.Fscan(in, &qq)

	for ii := 0; ii < qq; ii++ {
		var n int
//		fmt.Scan(&n)
		fmt.Fscan(in, &n)
		var a [102400]int
		for i := 0; i < n; i++ {
//			fmt.Scan(&a[i])
			fmt.Fscan(in, &a[i])
		}
		var l int = 0
		var r int = n - 1
		for ; l <= r && a[l] == 0; l++ {}
		for ; l <= r && a[r] == 0; r-- {}

		allz := true
		havez := false

		for i := l; i <= r; i++ {
			if a[i] != 0 {
				allz = false
			} else {
				havez = true
			}
		}

		if allz {
			fmt.Fprintln(out, 0)
		} else if havez {
			fmt.Fprintln(out, 2)
		} else {
			fmt.Fprintln(out, 1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var qq int
//	fmt.Scan(&qq)
	fmt.Fscan(in, &qq)

	for ii := 0; ii < qq; ii++ {
		var n int
//		fmt.Scan(&n)
		fmt.Fscan(in, &n)
		var a [102400]int
		for i := 0; i < n; i++ {
//			fmt.Scan(&a[i])
			fmt.Fscan(in, &a[i])
		}
		var l int = 0
		var r int = n - 1
		for ; l <= r && a[l] == 0; l++ {}
		for ; l <= r && a[r] == 0; r-- {}

		allz := true
		havez := false

		for i := l; i <= r; i++ {
			if a[i] != 0 {
				allz = false
			} else {
				havez = true
			}
		}

		if allz {
			fmt.Println(0)
		} else if havez {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"bufio"
	"os"
)

func Solve(testCaseIdx int, reader io.Reader) {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscan(reader, &n)
	cnt := 0
	inside := 0
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		if ak == 0 {
			cnt += inside
			inside = 0
		} else {
			inside = 1
		}
	}

	cnt += inside

	if cnt > 2 {
		cnt = 2
	}

	fmt.Fprintln(writer, cnt)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		/* var n, z int
		// n
		// x
		// k 有多少个土豆
		// =>x

		Fscan(in, &n, &z)
		var ans int
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		for i := 0; i < n; i++ {
			if arr[i]|z > ans {
				ans = arr[i] | z
			}
		}
		Fprintln(out, ans) */
		var n, i, j, k int
		Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		i, j = 0, n-1
		for i < n && a[i] == 0 {
			i++
		}
		for j >= 0 && a[j] == 0 {
			j--
		}
		if i > j {
			Fprintln(out, 0)
			return
		}
		for k = i + 1; k < j; k++ {
			if a[k] == 0 {
				break
			}
		}
		if k >= j {
			Fprintln(out, 1)
		} else {
			Fprintln(out, 2)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

import (
	"bufio"
	"fmt"
	"os"
)

func maxInt(a int, b int) int {
	if a >= b {
		return a
	}

	return b
}

func main() {
	//f, _ := os.Open("input.txt")
	var reader = bufio.NewReader(os.Stdin)
	//var reader = bufio.NewReader(f)
	var tests int
	fmt.Fscan(reader, &tests)
	for t := 0; t < tests; t++ {
		var n int
		fmt.Fscan(reader, &n)
		var zeroCount = 0
		var intervals = 0
		var previous = 0
		for i := 0; i < n; i++ {
			var next int
			fmt.Fscan(reader, &next)
			if next == 0 {
				zeroCount++
			} else {
				if previous == 0 {
					intervals++
				}
			}

			previous = next
		}

		if zeroCount == n {
			fmt.Println(0)
		} else {
			if intervals > 1 {
				fmt.Println(2)
			} else {
				fmt.Println(1)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
5
1
0
2
0 0
8
4 2 3 1 0 2 0 0
4
0 1 5 0
6
4 2 5 5 6 4
---
0
0
2
1
1
=======
7
1
5
10
3 5 3 0 0 3 5 4 2 0
2
0 5
2
5 0
8
3 0 5 1 0 5 6 1
5
0 0 5 0 0
5
0 5 5 0 0
---
1
2
1
1
2
1
1
=======
4
2
0 1
3
0 2 0
4
0 1 0 2
5
0 1 0 2 0
---
1
1
2
2
=======
3
2
1 0
3
1 0 1
4
1 0 1 0
---
1
2
2
=======
1
13
0 1 0 2 0 1 0 1 2 1 0 2 1

---
2
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	cnt := 0

	prev := 0

	for _, cur := range a {
		if prev != 0 && cur == 0 {
			cnt++
		}

		prev = cur
	}

	if prev != 0 {
		cnt++
	}

	fmt.Fprintln(writer, min(2, cnt))
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, nonZeroSegs, prv int
		_, _ = fmt.Fscan(r, &n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			if x != 0 && prv == 0 {
				nonZeroSegs++
			}
			prv = x
		}
		fmt.Fprintln(w, min(nonZeroSegs, 2))
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		non_zero := false
		zero := false
		zero_after_non_zero := false
		non_zero_after_zero := false
		more := false
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			if zero_after_non_zero && a[i] != 0 {
				more = true
			}
			if non_zero_after_zero && a[i] == 0 {
				more = true
			}
			if zero && a[i] != 0 {
				non_zero_after_zero = true
			}
			if non_zero && a[i] == 0 {
				zero_after_non_zero = true
			}
			if a[i] == 0 {
				zero = true
			} else {
				non_zero = true
			}
		}
		if more {
			fmt.Println(2)
		} else {
			if non_zero {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}

	}
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		started := false
		if a[0] != 0 {
			started = true
		}
		ans := 0
		for i := 1; i < n; i++ {
			if started {
				if a[i] == 0 {
					ans++
					started = false
				}
			} else {
				if a[i-1] == 0 && a[i] != 0 {
					started = true
				}
			}
		}
		if a[n-1] != 0 && started {
			ans++
		}
		fmt.Println(ans)
	}
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		started := false
		if a[0] != 0 {
			started = true
		}
		ans := 0
		for i := 1; i < n; i++ {
			if started {
				if a[i] == 0 {
					ans++
					started = false
				}
			} else {
				if a[i-1] == 0 && a[i] != 0 {
					started = true
				}
			}
		}
		if a[n-1] != 0 {
			ans++
		}
		fmt.Println(ans)
	}
}

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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		var ans int
		var f bool
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			if v == 0 {
				f = false
			} else {
				if !f {
					ans++
					f = true
				}
			}
		}

		fmt.Fprintln(out, ans)
	}
}

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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		aa := make([]int, n)
		var z int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
			if aa[i] == 0 {
				z++
			}
		}

		var ans int
		if z == n {
			ans = 0
		} else if z == 1 && (aa[0] == 0 || aa[n-1] == 0) {
			ans = 1
		} else if z == 0 {
			ans = 1
		} else {
			ans = 2
		}
		fmt.Fprintln(out, ans)
	}
}

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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		aa := make([]int, n)
		var z int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
			if aa[i] == 0 {
				z++
			}
		}

		var ans int
		if z == 1 && (aa[0] == 0 || aa[n-1] == 0) {
			ans = 1
		} else if z == 0 {
			ans = 1
		} else if z == n {
			ans = 0
		} else {
			ans = 2
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import (
	"fmt"
	"io"
	"bufio"
	"os"
)

func Solve(testCaseIdx int, reader io.Reader) {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscan(reader, &n)
	cnt := 0
	interval := 0
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		if ak == 0 {
			cnt += interval
			interval = 0
		} else {
			interval = 1
		}
	}
	cnt += interval

	fmt.Fprintln(writer, cnt)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		/* var n, z int
		// n
		// x
		// k 有多少个土豆
		// =>x

		Fscan(in, &n, &z)
		var ans int
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		for i := 0; i < n; i++ {
			if arr[i]|z > ans {
				ans = arr[i] | z
			}
		}
		Fprintln(out, ans) */
		var n, i, cnt int
		Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		for i < n {
			for i < n && a[i] == 0 {
				i++
			}
			if i < n {
				cnt++
			}
			for i < n && a[i] > 0 {
				i++
			}
		}
		Fprintln(out, cnt)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

import (
	"bufio"
	"fmt"
	"os"
)

func maxInt(a int, b int) int {
	if a >= b {
		return a
	}

	return b
}

func main() {
	//f, _ := os.Open("input.txt")
	var reader = bufio.NewReader(os.Stdin)
	//var reader = bufio.NewReader(f)
	var tests int
	fmt.Fscan(reader, &tests)
	for t := 0; t < tests; t++ {
		var n int
		fmt.Fscan(reader, &n)
		var zeroCount = 0
		var intervals = 0
		var previous = 0
		for i := 0; i < n; i++ {
			var next int
			fmt.Fscan(reader, &next)
			if next == 0 {
				zeroCount++
				if previous != 0 {
					intervals++
				}
			}

			previous = next
		}

		if zeroCount == n {
			fmt.Println(0)
		} else {
			if intervals > 1 {
				fmt.Println(2)
			} else {
				fmt.Println(1)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
2
8
4 2 3 1 0 2 0 0
4
0 1 5 0
---
2
1
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	cnt := 0

	prev := 0

	for _, cur := range a {
		if prev != 0 && cur == 0 {
			cnt++
		}

		prev = cur
	}

	if prev != 0 {
		cnt++
	}

	fmt.Fprintln(writer, cnt)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}


You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:  A "+" shape has one center nonempty cell.  There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.  All other cells are empty. Find out if the given picture has single "+" shape.

The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.

If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).

NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

type pic [][2]int

func (s pic) Len() int {
	return len(s)
}
func (s pic) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s pic) Less(i, j int) bool {

	if s[i][0] < s[j][0] {
		return true
	}
	if s[i][0] == s[j][0] {
		return s[i][1] < s[j][1]
	}
	return false
}

func checkline(p pic) bool {
	var s = 0
	var n = len(p)
	var jstart = p[0][1]
	var xvert = -1
	for i := 1; i < n; i++ {
		if p[i][0]-p[i-1][0] > 1 {
			return false
		}

		if p[i][1] != jstart {
			if xvert == -1 {
				xvert = p[i][0]
			} else {
				if xvert != p[i][0] {
					return false
				}

			}
		}

		if p[i][0]-p[i-1][0] == 1 && !(p[i-1][1] == jstart || p[i][1] == jstart) {
			return false
		}
		if p[i][1] == jstart {
			s = s + 1
		}
	}

	return s == p[n-1][0]-p[0][0]

}

func main() {
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)
	var h, w int
	var ph pic
	var pv pic
	fmt.Fscan(read, &h, &w)
	for i := 0; i < h; i++ {
		var s string
		fmt.Fscan(read, &s)
		ln := strings.Split(s, "")
		for j := 0; j < w; j++ {
			if ln[j] == "*" {
				t := [2]int{i, j}
				ph = append(ph, t)
				t = [2]int{j, i}
				pv = append(pv, t)
			}
		}

	}
	var lp = len(ph)
	var res = "NO"

	if lp > 0 {
		sort.Sort(ph)
		sort.Sort(pv)

		check := checkline(ph)

		if check {
			check = checkline(pv)

		}
		if check {
			check = (pv[0][0] < ph[0][1] && pv[lp-1][0] > ph[0][1]) &&
				(ph[0][0] < pv[0][1] && ph[lp-1][0] > pv[0][1])
		}

		if check {
			res = "YES"
		}
	}

	fmt.Fprint(write, res)
	write.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// var a string
	var n, t, cnt, last2, res, d, last, last1 int
	// var x float64
	// var s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &t)

	a := make([][]string, n)
	b := make([]int, 0)

	m := make(map[int][]int)
	for i := 0; i < n; i++ {
		a[i] = make([]string, t)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < t; j++ {
			fmt.Fscanf(scr, "%1v", &a[i][j])
			if string(a[i][j]) == "*" {
				m[i] = append(m[i], j)
				if len(m) == 1 {
					last = j
				}
			}
		}
		fmt.Fscanln(scr, &d)
	}

oc:
	for x, y := range m {
		if len(y) > 1 {
			cnt++
			if cnt > 1 {
				res = 5
				break
			}
			if last < y[1] || last > y[len(y)-2] {
				res = 5
				break
			}
			for x, y := range y {
				if (x > 0) && (y != last1+1) {
					res = 5
					break oc
				}
				last1 = y
			}
			last2 = x
			b = append(b, x)
		} else {
			b = append(b, x)
			if y[0] != last {
				res = 5
				break
			}
		}
	}
	cnt = 0
	if res != 5 {
		sort.Ints(b)
		if len(b) <= 1 || last2 <= b[0] || last2 >= b[len(b)-1] {
			res = 5
		}
		if res != 5 {
			for x, y := range b {
				if (x > 0) && (y != last2+1) {
					res = 5
					break
				}
				last2 = y
			}
		}
	}

	if res == 5 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scanf("%d %d\n", &h, &w)
	pict := make([]rune, w*h)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			fmt.Scanf("%c", &pict[i*w+j])
		}
		fmt.Scanln()
	}
	if Solve(h, w, pict) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func Solve(h, w int, pict []rune) bool {
	var ci, cj int
	for i := 1; i < h-1; i++ {
		for j := 1; j < w-1; j++ {
			if pict[i*w+j] == '*' && pict[(i-1)*w+j] == '*' && pict[i*w+j+1] == '*' && pict[(i+1)*w+j] == '*' && pict[i*w+j-1] == '*' {
				ci, cj = i, j
				break
			}
		}
	}
	if ci == 0 || cj == 0 {
		return false
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if i != ci && j != cj && pict[i*w+j] == '*' {
				return false
			}
		}
	}

	for i := ci - 1; i >= 0; i-- {
		if pict[i*w+cj] == '*' && pict[(i+1)*w+cj] != '*' {
			return false
		}
	}
	for i := ci + 1; i < h; i++ {
		if pict[i*w+cj] == '*' && pict[(i-1)*w+cj] != '*' {
			return false
		}
	}
	for j := cj - 1; j >= 0; j-- {
		if pict[ci*w+j] == '*' && pict[ci*w+j+1] != '*' {
			return false
		}
	}
	for j := cj + 1; j < w; j++ {
		if pict[ci*w+j] == '*' && pict[ci*w+j-1] != '*' {
			return false
		}
	}

	return true
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	a := make([]string, n)
	cnt := 0
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%s\n", &a[i])
		for j := 0; j < m; j++ {
			if a[i][j] == '*' {
				cnt++
			}
		}
	}
	centerx := -1
	centery := -1
	for i := 1; i < n-1; i++ {
		for j := 1; j < m-1; j++ {
			if a[i][j] == '*' && a[i+1][j] == '*' && a[i-1][j] == '*' && a[i][j+1] == '*' && a[i][j-1] == '*' &&
				a[i+1][j+1] == '.' && a[i+1][j-1] == '.' && a[i-1][j+1] == '.' && a[i-1][j-1] == '.' {
				if centerx != -1 {
					fmt.Fprintf(out, "NO\n")
					return
				}
				centerx = i
				centery = j
			}
		}
	}
	if centerx == -1 {
		fmt.Fprintf(out, "NO\n")
		return
	}
	cnt--
	for i := centerx + 1; i < n; i++ {
		if a[i][centery] == '.' {
			break
		}
		cnt--
	}
	for i := centerx - 1; i >= 0; i-- {
		if a[i][centery] == '.' {
			break
		}
		cnt--
	}
	for i := centery + 1; i < m; i++ {
		if a[centerx][i] == '.' {
			break
		}
		cnt--
	}
	for i := centery - 1; i >= 0; i-- {
		if a[centerx][i] == '.' {
			break
		}
		cnt--
	}
	if cnt == 0 {
		fmt.Fprintf(out, "YES\n")
		return
	}
	fmt.Fprintf(out, "NO\n")
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
)

var DEBUG = true

func main() {
	defer Flush()

	h := readi()
	w := readi()
	s := make([][]byte, h)
	for i := range s {
		s[i] = readb()
	}

	if solve(h, w, s) {
		println("YES")
	} else {
		println("NO")
	}
}

func solve(h, w int, s [][]byte) bool {

	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}
	y := -1
	x := -1
	found := false
outer:
	for i := 1; i < h-1; i++ {
	jloop:
		for j := 1; j < w-1; j++ {
			if s[i][j] != '*' {
				continue
			}
			for k := range dx {
				nx := j + dx[k]
				ny := i + dy[k]
				if s[ny][nx] != '*' {
					continue jloop
				}
			}

			found = true
			y = i
			x = j
			break outer
		}
	}

	if !found {
		return false
	}

	s[y][x] = '.'
	for k := range dx {
		nx := x + dx[k]
		ny := y + dy[k]
		dfs(h, w, s, ny, nx, dy[k], dx[k])

	}

	for i := range s {
		for j := range s[i] {
			if s[i][j] == '*' {
				return false
			}
		}
	}

	return true
}

func dfs(h, w int, s [][]byte, y, x, dy, dx int) {
	if y < 0 || h <= y || x < 0 || w <= x {
		return
	}

	if s[y][x] != '*' {
		return
	}

	s[y][x] = '.'
	dfs(h, w, s, y+dy, x+dx, dy, dx)
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func readInt(reader *bufio.Scanner) int {
	var result int
	reader.Scan()
	result, _ = strconv.Atoi(reader.Text())
	return result
}

func findCenter(tiles [][]bool, h int, w int, c_r int, c_c int) (int, int, bool) {
	error := false
	for i := 1; i < h-1; i++ {
		for j := 1; j < w-1; j++ {
			if tiles[i][j] && tiles[i][j+1] && tiles[i][j-1] && tiles[i+1][j] && tiles[i-1][j] {
				if c_c < 0 && c_r < 0 {
					c_r = i
					c_c = j
				} else {
					error = true
				}
			}
		}
	}
	if error || c_r < 0 || c_c < 0 {
		return -1, -1, true
	} else {
		return c_r, c_c, false
	}
}

func checkEmptySpacesAcc(tiles [][]bool, h0 int, h1 int, w0 int, w1 int) bool {
	for i := h0; i < h1; i++ {
		for j := w0; j < w1; j++ {
			if tiles[i][j] {
				return true
			}
		}
	}
	return false
}

func checkEmptySpaces(tiles [][]bool, h int, w int, c_r int, c_c int) bool {
	var error bool = false
	error = error || checkEmptySpacesAcc(tiles, 0, c_r, 0, c_c)
	error = error || checkEmptySpacesAcc(tiles, c_r+1, h, 0, c_c)
	error = error || checkEmptySpacesAcc(tiles, 0, c_r, c_c+1, w)
	error = error || checkEmptySpacesAcc(tiles, c_r+1, h, c_c+1, w)
	return error
}

func main() {
	var error bool = false
	reader := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 2)
	reader.Buffer(buf, 501)
	reader.Split(bufio.ScanWords)
	h := readInt(reader)
	w := readInt(reader)
	tiles := make([][]bool, h)
	for i := 0; i < h; i++ {
		tiles[i] = make([]bool, w)
	}
	for i := 0; i < h; i++ {
		reader.Scan()
		str := reader.Text()
		rn := []rune(str)
		for j := 0; j < w; j++ {
			tiles[i][j] = rn[j] == '*'
		}
	}
	// Find center
	c_r := -1
	c_c := -1
	c_r, c_c, error = findCenter(tiles, h, w, c_r, c_c)
	if error {
		fmt.Println("NO")
		return
	}
	// Check empty spaces
	error = checkEmptySpaces(tiles, h, w, c_r, c_c)
	if error {
		fmt.Println("NO")
		return
	}
	// check row
	var seen bool = false
	var gap bool = false
	for i := 0; i < w; i++ {
		if tiles[c_r][i] {
			if !seen {
				seen = true
			} else if gap {
				fmt.Println("NO")
				return
			}
		} else if seen {
			gap = true
		}
	}
	seen = false
	gap = false
	for i := 0; i < h; i++ {
		if tiles[i][c_c] {
			if !seen {
				seen = true
			}
			if gap {
				fmt.Println("NO")
				return
			}
		}else if seen{
			gap = true
		}
	}
	fmt.Println("YES")
}

// Author: sighduck
// URL: https://codeforces.com/contest/1182/problem/B

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Cell struct {
	X int
	Y int
}

func isCenter(i int, j int, pictureMatrix [][]bool) bool {
	return pictureMatrix[i][j] &&
		pictureMatrix[i-1][j] &&
		pictureMatrix[i+1][j] &&
		pictureMatrix[i][j-1] &&
		pictureMatrix[i][j+1]
}

func createPictureMatrix(picture []string, h int, w int) [][]bool {
	pictureMatrix := make([][]bool, h)
	for i := 0; i < h; i++ {
		pictureMatrix[i] = make([]bool, w)
		for j := 0; j < w; j++ {
			if string(picture[i][j]) == "*" {
				pictureMatrix[i][j] = true
			}
		}
	}
	return pictureMatrix
}

func Solve(h int, w int, picture []string) string {
	pictureMatrix := createPictureMatrix(picture, h, w)
	centers := []Cell{}
	for i := 1; i < h-1; i++ {
		for j := 1; j < w-1; j++ {
			if isCenter(i, j, pictureMatrix) {
				centers = append(centers, Cell{X: i, Y: j})
			}
		}
	}
	if len(centers) != 1 {
		return "NO"
	}
	center := centers[0]
	for i := center.X - 1; i >= 0; i-- {
		if pictureMatrix[i][center.Y] {
			pictureMatrix[i][center.Y] = false
		} else {
			break
		}
	}
	for i := center.X + 1; i < h; i++ {
		if pictureMatrix[i][center.Y] {
			pictureMatrix[i][center.Y] = false
		} else {
			break
		}
	}
	for j := center.Y - 1; j >= 0; j-- {
		if pictureMatrix[center.X][j] {
			pictureMatrix[center.X][j] = false
		} else {
			break
		}
	}
	for j := center.Y + 1; j < w; j++ {
		if pictureMatrix[center.X][j] {
			pictureMatrix[center.X][j] = false
		} else {
			break
		}
	}
	pictureMatrix[center.X][center.Y] = false
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if pictureMatrix[i][j] {
 				return "NO"
			}
		}
	}
	return "YES"
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var h int
	var w int
	fmt.Fscanf(reader, "%d %d\n", &h, &w)
	picture := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Fscanf(reader, "%s\n", &picture[i])
	}
	fmt.Fprintf(writer, "%s\n", Solve(h, w, picture))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

type pic [][2]int

func (s pic) Len() int {
	return len(s)
}
func (s pic) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s pic) Less(i, j int) bool {

	if s[i][0] < s[j][0] {
		return true
	}
	if s[i][0] == s[j][0] {
		return s[i][1] < s[j][1]
	}
	return false
}

func checkline(p pic) bool {
	var s = 0
	var n = len(p)
	var jstart = p[0][1]
	for i := 1; i < n; i++ {
		if p[i][0]-p[i-1][0] > 1 {
			return false
		}

		if p[i][0]-p[i-1][0] == 1 && !(p[i-1][1] == jstart || p[i][1] == jstart) {
			return false
		}
		if p[i][1] == jstart {
			s = s + 1
		}
	}

	return s == p[n-1][0]-p[0][0]

}

func main() {
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)
	var h, w int
	var ph pic
	var pv pic
	fmt.Fscan(read, &h, &w)
	for i := 0; i < h; i++ {
		var s string
		fmt.Fscan(read, &s)
		ln := strings.Split(s, "")
		for j := 0; j < w; j++ {
			if ln[j] == "*" {
				t := [2]int{i, j}
				ph = append(ph, t)
				t = [2]int{j, i}
				pv = append(pv, t)
			}
		}

	}
	var lp = len(ph)
	var res = "NO"

	if lp > 0 {
		sort.Sort(ph)
		sort.Sort(pv)

		check := checkline(ph)

		if check {
			check = checkline(pv)

		}
		if check {
			check = (pv[0][0] < ph[0][1] && pv[lp-1][0] > ph[0][1]) &&
				(ph[0][0] < pv[0][1] && ph[lp-1][0] > pv[0][1])
		}

		if check {
			res = "YES"
		}
	}

	fmt.Fprint(write, res)
	write.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// var a string
	var n, t, cnt, last2, res, d, last, last1 int
	// var x float64
	// var s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &t)

	a := make([][]string, n)
	b := make([]int, 0)

	m := make(map[int][]int)
	for i := 0; i < n; i++ {
		a[i] = make([]string, t)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < t; j++ {
			fmt.Fscanf(scr, "%1v", &a[i][j])
			if string(a[i][j]) == "*" {
				m[i] = append(m[i], j)
				if len(m) == 1 {
					last = j
				}
			}
		}
		fmt.Fscanln(scr, &d)
	}

oc:
	for x, y := range m {
		if len(y) > 1 {
			cnt++
			if cnt > 1 {
				res = 5
				break
			}
			if last < y[1] || last > y[len(y)-2] {
				res = 5
				break
			}
			for x, y := range y {
				if (x > 0) && (y != last1+1) {
					res = 5
					break oc
				}
				last1 = y
			}
			last2 = x
			b = append(b, x)
		} else {
			b = append(b, x)
			if y[0] != last {
				res = 5
				break
			}
		}
	}
	fmt.Println(b)
	cnt = 0
	if res != 5 {
		sort.Ints(b)
		if len(b) <= 1 || last2 <= b[0] || last2 >= b[len(b)-1] {
			res = 5
		}
		if res != 5 {
			for x, y := range b {
				if (x > 0) && (y != last2+1) {
					res = 5
					break
				}
				last2 = y
			}
		}
	}

	if res == 5 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// var a string
	var n, t, cnt, last2, res, d, last, last1 int
	// var x float64
	// var s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &t)

	a := make([][]string, n)
	b := make([]int, 0)

	m := make(map[int][]int)
	for i := 0; i < n; i++ {
		a[i] = make([]string, t)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < t; j++ {
			fmt.Fscanf(scr, "%1v", &a[i][j])
			if string(a[i][j]) == "*" {
				m[i] = append(m[i], j)
				if len(m) == 1 {
					last = j
				}
			}
		}
		fmt.Fscanln(scr, &d)
	}

oc:
	for x, y := range m {
		if len(y) > 1 {
			cnt++
			if cnt > 1 {
				res = 5
				break
			}
			if last < y[1] || last > y[len(y)-2] {
				res = 5
				break
			}
			for x, y := range y {
				if (x > 0) && (y != last1+1) {
					res = 5
					break oc
				}
				last1 = y
			}
			last2 = x
		} else {
			b = append(b, x)
			if y[0] != last {
				res = 5
				break
			}
		}
	}
	if res != 5 {
		sort.Ints(b)
		if last2 < b[1] || last2 > b[len(b)-2] {
			res = 5
		}
		if res != 5 {
			for x, y := range b {
				if (x > 0) && (y != last2+1) {
					res = 5
					break
				}
				last2 = y
			}
		}
	}

	if res == 5 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// var a string
	var n, t, cnt, res, d, last, last1 int
	// var x float64
	// var s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &t)

	a := make([][]string, n)
	m := make(map[int][]int)
	for i := 0; i < n; i++ {
		a[i] = make([]string, t)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < t; j++ {
			fmt.Fscanf(scr, "%1v", &a[i][j])
			if string(a[i][j]) == "*" {
				m[i] = append(m[i], j)
				if len(m) == 1 {
					last = j
				}
			}
		}
		fmt.Fscanln(scr, &d)
	}

oc:
	for _, y := range m {
		if len(y) > 1 {
			cnt++
			if cnt > 1 {
				res = 5
				break
			}
			sort.Ints(y)
			if last < y[1] || last > y[len(y)-2] {
				res = 5
				break
			}
			for x, y := range y {
				if (x > 0) && (y != last1+1) {
					res = 5
					break oc
				}
				last1 = y
			}
		} else {
			if y[0] != last {
				res = 5
				break
			}
		}
	}

	if res == 5 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// var a string
	var n, t, cnt, last2, res, d, last, last1 int
	// var x float64
	// var s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &t)

	a := make([][]string, n)
	b := make([]int, 0)

	m := make(map[int][]int)
	for i := 0; i < n; i++ {
		a[i] = make([]string, t)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < t; j++ {
			fmt.Fscanf(scr, "%1v", &a[i][j])
			if string(a[i][j]) == "*" {
				m[i] = append(m[i], j)
				if len(m) == 1 {
					last = j
				}
			}
		}
		fmt.Fscanln(scr, &d)
	}

oc:
	for x, y := range m {
		if len(y) > 1 {
			cnt++
			if cnt > 1 {
				res = 5
				break
			}
			if last < y[1] || last > y[len(y)-2] {
				res = 5
				break
			}
			for x, y := range y {
				if (x > 0) && (y != last1+1) {
					res = 5
					break oc
				}
				last1 = y
			}
			last2 = x
		} else {
			b = append(b, x)
			if y[0] != last {
				res = 5
				break
			}
		}
	}
	cnt = 0
	if res != 5 {
		sort.Ints(b)
		fmt.Println(b)
		if last2 <= b[0] || last2 >= b[len(b)-1] {
			res = 5
		}
		if res != 5 {
			for x, y := range b {
				if (x > 0) && (y != last2+1) {
					cnt++
					if cnt > 1 {
						res = 5
						break
					}
				}
				last2 = y
			}
		}
	}

	if res == 5 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// var a string
	var n, t, cnt, last2, res, d, last, last1 int
	// var x float64
	// var s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &t)

	a := make([][]string, n)
	b := make([]int, 0)

	m := make(map[int][]int)
	for i := 0; i < n; i++ {
		a[i] = make([]string, t)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < t; j++ {
			fmt.Fscanf(scr, "%1v", &a[i][j])
			if string(a[i][j]) == "*" {
				m[i] = append(m[i], j)
				if len(m) == 1 {
					last = j
				}
			}
		}
		fmt.Fscanln(scr, &d)
	}

oc:
	for x, y := range m {
		if len(y) > 1 {
			cnt++
			if cnt > 1 {
				res = 5
				break
			}
			if last < y[1] || last > y[len(y)-2] {
				res = 5
				break
			}
			for x, y := range y {
				if (x > 0) && (y != last1+1) {
					res = 5
					break oc
				}
				last1 = y
			}
			last2 = x
		} else {
			b = append(b, x)
			if y[0] != last {
				res = 5
				break
			}
		}
	}
	cnt = 0
	if res != 5 {
		sort.Ints(b)
		if len(b) <= 1 || last2 <= b[0] || last2 >= b[len(b)-1] {
			res = 5
		}
		if res != 5 {
			for x, y := range b {
				if (x > 0) && (y != last2+1) {
					cnt++
					if cnt > 1 {
						res = 5
						break
					}
				}
				last2 = y
			}
		}
	}

	if res == 5 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}


Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $$$i$$$ ($$$1 \le i \le n-1$$$), this condition must be satisfied: $$$$$$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \le 2$$$$$$For example, the arrays $$$[1, 2, 3, 4, 3]$$$, $$$[1, 1, 1]$$$ and $$$[5, 10]$$$ are dense. And the arrays $$$[5, 11]$$$, $$$[1, 4, 2]$$$, $$$[6, 6, 1]$$$ are not dense.You are given an array $$$a$$$ of $$$n$$$ integers. What is the minimum number of numbers you need to add to an array to make it dense? You can insert numbers anywhere in the array. If the array is already dense, no numbers need to be added.For example, if $$$a=[4,2,10,1]$$$, then the answer is $$$5$$$, and the array itself after inserting elements into it may look like this: $$$a=[4,2,\underline{\textbf{3}},\underline{\textbf{5}},10,\underline{\textbf{6}},\underline{\textbf{4}},\underline{\textbf{2}},1]$$$ (there are other ways to build such $$$a$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 50$$$).

For each test case, output one integer — the minimum number of numbers that must be added to the array to make it dense.

NoteThe first test case is explained in the statements.In the second test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},3]$$$.In the third test case, you can insert two elements, $$$a=[6,\underline{\textbf{4}},\underline{\textbf{2}},1]$$$.In the fourth test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},4,2]$$$.In the fifth test case, the array $$$a$$$ is already dense.

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := getIntln(reader)
		var res, a, b int
		for i := 1; i < n; i++ {
			if A[i] > A[i-1] {
				a, b = A[i], A[i-1]
			} else if A[i] == A[i-1] {
				continue
			} else {
				a, b = A[i-1], A[i]
			}
			y := math.Log2(float64(a) / float64(b))
			if y-math.Floor(y) > 0.025 {
				y = math.Ceil(y)
			}
			res += int(y) - 1
		}
		writer.WriteString(fmt.Sprintln(res))
	}

	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import (
	"fmt"
	"math"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		ans := 0
		arr := make([]float64, n+1)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
			if j > 0 && arr[j] != arr[j-1] {
				ans += int(math.Ceil(math.Log2(math.Max(arr[j-1], arr[j]) / math.Min(arr[j-1], arr[j])))) - 1
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

type Pair struct {
	a, b int64
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	t := getI()
	dp := make(map[Pair]int64)

	forEach(t, func(i int64) {
		len := getI()
		nums := getInts(len)
		res := int64(0)
		forEach(len-1, func(j int64) {
			mi := min(nums[j], nums[j+1])
			ma := max(nums[j], nums[j+1])

			p := Pair{mi, ma}
			var tmp int64
			if val, ok := dp[p]; ok {
				res += val
			} else {
				for mi*2 < ma {
					tmp++
					res++
					mi *= 2
				}
				dp[p] = tmp
			}
		})
		out(res)
	})
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	t := getI()

	forEach(t, func(i int64) {
		len := getI()
		nums := getInts(len)
		res := 0
		forEach(len-1, func(j int64) {
			mi := min(nums[j], nums[j+1])
			ma := max(nums[j], nums[j+1])
			for mi*2 < ma {
				res++
				mi *= 2
			}
		})
		out(res)
	})
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

func MIN(x, y int) float64 {
	if x > y {
		return float64(y)
	} else {
		return float64(x)
	}
}

func MAX(x, y int) float64 {
	if x > y {
		return float64(x)
	} else {
		return float64(y)
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		// // STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		countt := 0
		for i := 1; i < n; i++ {
			t := float64(MAX(ARRAY[i], ARRAY[i-1]) / MIN(ARRAY[i], ARRAY[i-1]))
			if t > 2 {
				countt = countt + 1
			}
			if t > 4 {
				countt = countt + 1
			}
			if t > 8 {
				countt = countt + 1
			}
			if t > 16 {
				countt = countt + 1
			}
			if t > 32 {
				countt = countt + 1
			}

		}
		fmt.Println(countt)

	}

}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

func MIN(x, y int) float64 {
	if x > y {
		return float64(y)
	} else {
		return float64(x)
	}
}

func MAX(x, y int) float64 {
	if x > y {
		return float64(x)
	} else {
		return float64(y)
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		// // STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		count := 0
		for i := 1; i < n; i++ {
			t := float64(MAX(ARRAY[i], ARRAY[i-1]) / MIN(ARRAY[i], ARRAY[i-1]))
			if t > 2 {
				count = count + 1
			}
			if t > 4 {
				count = count + 1
			}
			if t > 8 {
				count = count + 1
			}
			if t > 16 {
				count = count + 1
			}
			if t > 32 {
				count = count + 1
			}

		}
		fmt.Println(count)

	}

}

package main

import "fmt"

func missingNum(proportion float32) (missing int16) {
	var powerOfTwo int16 = 2
	missing = 0
	for float32(powerOfTwo) < proportion {
		powerOfTwo = (powerOfTwo << 1)
		missing++
	}
	return
}

func main() {
	var t uint16
	fmt.Scan(&t)
	var n int8
	var arr []float32
	var tmp float32
	var res int16
	var answer []int16
	var proportion float32

	for i := uint16(0); i < t; i++ {
		fmt.Scan(&n)
		for j := int8(0); j < n; j++ {
			fmt.Scan(&tmp)
			arr = append(arr, tmp)
			if j > 0 {
				proportion = arr[j-1] / arr[j]
				if proportion < 0.5 {
					proportion = 1 / proportion
				}
				if proportion > 2 {
					res += missingNum(proportion)
				}
			}
		}
		answer = append(answer, res)
		res = 0
		arr = nil
	}

	for _, val := range answer {
		fmt.Println(val)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var T, a, b, n int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var count int = 0
		fmt.Scan(&n, &a)
		for i := 1; i < n; i++ {
			fmt.Scan(&b)
			var x, y float64 = math.Min(float64(a), float64(b)), math.Max(float64(a), float64(b))
			for x * 2 < y {
				x *= 2
				count++
			}
			a = b
		}
		fmt.Println(count)
	}
}

package main

import (
    "bufio"
    "io"
    "os"
    . "fmt"
    . "math"
)
var input io.Reader = bufio.NewReader(os.Stdin)
func main() {
    var t int
    Fscan(input, &t)
    for i := 0; i < t; i++ {
        var n int
        Fscan(input, &n)
        a := make([]float64, n)

        ans := 0
        for i:= 0; i < n; i++ {
            Fscan(input, &a[i])
            if i != 0 && a[i-1] != a[i] {
                ans += int(Ceil(Log2(Max(a[i-1], a[i]) /
                        Min(a[i-1], a[i])))) -1
            }
        }
        Println(ans)
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func f(a []int) int {
	max := func(a, b int) int {
		if a >= b {
			return a
		}
		return b
	}
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}

	var res int
	for i := 0; i < len(a)-1; i++ {
		ma := max(a[i], a[i+1])
		mi := min(a[i], a[i+1])
		for ; mi*2 < ma; res++ {
			mi *= 2
		}

	}
	return res
}
func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; n > 0; n, i = n-1, i+1 {
			fmt.Fscan(in, &a[i])
		}
		fmt.Println(f(a))
	}
}

package main
import(
    "fmt"
    "math"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var list []int = make([]int,n)
		for j:=0;j<n;j++{
			fmt.Scan(&list[j])
		}
		counter:=0
		for j:=0;j<n-1;j++{
			if min(list[j],list[j+1])*2 < max(list[j],list[j+1]) {
				for k:=1;k<max(list[j],list[j+1]);k++{
					min_:= min(list[j],list[j+1])
					max_:= max(list[j],list[j+1])
					min_*= x_power_y(2,k)
					if max(list[j],list[j+1])%2!=0{
						if min_ > max_/2 {
							counter+=k
							break
						}
					} else {
						if min_ >= max_/2 {
							counter+=k
							break
						}
					}
				}
			}
		}
		fmt.Println(counter)
	}
}

func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}
func min (x,y int) int {
	if x<y{
		return x
	} else {
		return y
	}
}
func x_power_y(x,y int) int {
	//dependencies math
	return int(math.Pow(float64(x),float64(y)))
}

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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		var tot int
		for i := 1; i < n; i++ {
			a := arr[i-1]
			b := arr[i]
			if a > arr[i] {
				a, b = b, a
			}

			for a*2 < b {
				a *= 2
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func ICeil(x float64) int64 {
	return int64(math.Ceil(x))
}

func check(b, a int) int {
	o := 0
	for {
		a = int(ICeil(float64(a) / 2.0))
		if a <= b {
			break
		}
		o++
	}
	return o
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, p, tot := []int{}, 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o = append(o, p)
		}
		for j := 0; j < n-1; j++ {
			if o[j+1] > 2*o[j] {
				tot += check(o[j], o[j+1])
			} else if o[j] > 2*o[j+1] {
				tot += check(o[j+1], o[j])
			}
		}
		fmt.Fprintln(w, tot)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) int {
	var (
		c int
		k float64
	)
	for i := 1; i < n; i++ {
		k = float64(a[i]) / float64(a[i-1])
		if a[i] < a[i-1] {
			k = float64(a[i-1]) / float64(a[i])
		}
		for k > 2 {
			k /= 2
			c++
		}
	}
	return c
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func minimum(a int32, b int32) int32 {
	if a < b {
		return a
	} else {
		return b
	}
}

func maximum(a int32, b int32) int32 {
	if a < b {
		return b
	} else {
		return a
	}
}

func dense(a int32, b int32) int32 {
	mini := minimum(a, b)
	maxi := maximum(a, b)
	output := int32(0)
	for mini*2 < maxi {
		mini *= 2
		output++
	}
	return output
}

func solve(n int32, arr []int32) int32 {
	output := int32(0)
	for i := int32(1); i < n; i++ {
		output += dense(arr[i-1], arr[i])
	}
	return output
}

func arrayScanf(in *bufio.Reader, n int32, arr *[]int32) {
	m := int32(0)
	for i := int32(0); i < n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		*arr = append(*arr, m)
	}
	fmt.Fscanf(in, "\n")
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		arr := []int32{}
		fmt.Fscanf(in, "%d\n", &n)
		arrayScanf(in, n, &arr)

		fmt.Fprintf(out, "%d\n", solve(n, arr))
		tt--
	}
	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

type CF1490A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1490A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1490A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1490A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1490A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1490A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

func (in *CF1490A) Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (in *CF1490A) Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

/**
 Run solve the problem CF1490A
 Date: 25/05/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1490/A
 Problem: CF1490A
**/
func (in *CF1490A) Run() {

	t := in.NextInt()

	for ; t > 0; t-- {
		n := in.NextInt()
		var arr []int
		for ; n > 0; n-- {
			val := in.NextInt()
			arr = append(arr, val)
		}

		var sol []int
		for i := 0; i < len(arr); i++ {
			if i > 0 {
				for in.Min(sol[len(sol)-1], arr[i])*2 < in.Max(sol[len(sol)-1], arr[i]) {
					if arr[i] == in.Min(sol[len(sol)-1], arr[i]) {
						sol = append(sol, int(math.Ceil(float64(sol[len(sol)-1])/2.0)))
					} else {
						sol = append(sol, sol[len(sol)-1]*2)
					}
				}
			}
			sol = append(sol, arr[i])
		}
		//fmt.Println("sol", sol)
		fmt.Println(len(sol) - len(arr))
	}
}

func NewCF1490A(r *bufio.Reader) *CF1490A {
	return &CF1490A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1490A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, n, a, la int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &la)
		count := 0
		for j := 1; j < n; j++ {
			fmt.Fscan(in, &a)
			count += addDense(la, a)
			la = a
		}
		fmt.Println(count)
	}
}

func addDense(a, b int) int {
	min, max := sort2(a, b)
	count := 0
	for min*2 < max {
		count++
		min *= 2
	}
	return count
}

func sort2(a, b int) (int, int) {
	if a < b {
		return a, b
	}
	return b, a
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(A []int) int {
	n := len(A)

	var res int

	for i := 0; i < n-1; i++ {
		res += makeDense(A[i], A[i+1])
	}

	return res
}

func makeDense(a, b int) int {
	if a > b {
		a, b = b, a
	}
	var res int
	for a*2 < b {
		res++
		a *= 2
	}

	return res
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func scanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		a := make([]int, n)

		for i := 0; i < n; i++ {
			a[i] = scanInt()
		}

		toAdd := 0
		for i := 1; i < n; i++ {
			min := min(a[i-1], a[i])
			max := max(a[i-1], a[i])

			for max > 2*min {
				toAdd++
				min *= 2
			}
		}

		fmt.Println(toAdd)
	}
}

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}

	return y
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func max (a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	var t int
	fmt.Scan(&t)
	for test := 0; test < t; test++ {
		var n int
		fmt.Scan(&n)
		var arr []int = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&arr[i])
		}
		ans := 0
		for i := 0; i < n - 1; i++ {
			l := min(arr[i], arr[i + 1])
			r := max(arr[i], arr[i + 1])
			for ; r > 2*l; {
				l *= 2
				ans++
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"math"
)

func min(a int, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a int, b int) int {
	if a >= b {
		return a
	}
	return b
}

func main() {
	var t int
	_, _ = fmt.Scan(&t)

	for t > 0 {
		var n int
		_, _ = fmt.Scan(&n)

		var a = make([]int, n, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Scan(&a[i])
		}

		var ans int
		for i := 1; i < n; i++ {
			var r = math.Abs(math.Log2(float64(a[i])) - math.Log2(float64(a[i-1]))) - 1e-4
			if r > 1 {
				ans += int(math.Floor(r))
			}
		}
		fmt.Println(ans)

		t--
	}
}

package main

import "fmt"

func max(x, y int) (int, int) {
	if x > y {
		return y, x
	} else {
		return x, y
	}
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n, ans := 0, 0
		fmt.Scan(&n)
		a := make([]int, n)
		for i := range a {
			fmt.Scan(&a[i])
		}
		for i := 0; i < n-1; i++ {
			for s, l := max(a[i], a[i+1]); s*2 < l; {
				ans++
				s *= 2
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1490A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := 0
		for i := 1; i < n; i++ {
			v, w := a[i-1], a[i]
			if v < w {
				v, w = w, v
			}
			for ; v > 2*w; v = (v + 1) / 2 {
				ans++
			}
		}
		Fprintln(out, ans)
	}
}

func main() { CF1490A(os.Stdin, os.Stdout) }

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		ans1 := 0
		n := 0
		fmt.Scan(&n)
		var in1 [51]int
		for i := 1; i <= n; i++ {
			fmt.Scan(&in1[i])
		}
		for i := 1; i <= (n - 1); i++ {
			a1 := min(in1[i], in1[(i+1)])
			b1 := max(in1[i], in1[(i+1)])
			for ; (a1 * 2) < b1; {
				ans1++
				a1 *= 2
			}
		}
		fmt.Println(ans1)
	}
}

package main

import (
	. "fmt"
	"os"
	"bufio"
)

func min(a, b int) int{
	if a < b {
		return a;
	} else{
		return b;
	}
}
func max(a, b int) int{
	if a > b {
		return a;
	} else{
		return b;
	}
}
func main(){
	in := bufio.NewReader(os.Stdin);
	out := bufio.NewWriter(os.Stdout);
 	defer out.Flush();

 	var t int;
 	Fscan(in, &t);
 	for i:=0;i<t;i++ {
 		var n int;
 		Fscan(in, &n);

 		a := make([]int, n);
 		for i:=0;i<n;i++ {
 			Fscan(in, &a[i]);
 		}

 		ans := 0;
 		for i:=1;i<n;i++ {
 			mn := min(a[i-1], a[i]);
 			mx := max(a[i-1], a[i]);

 			for mn*2 < mx {
 				mn *= 2;
 				ans++;
 			}
 		}
 		Fprint(out, ans, "\n");
 	}
}

package main

import (
	"bufio"
	. "fmt"
	. "math"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n, no, c, t1, t2 int
	c = 0
	var line = make([]int, 0)
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &no)
			line = append(line, no)
		}
		t2 = line[0]
		for i := 1; i < len(line); i++ {
			t1 = t2
			t2 = line[i]
			if t1 > t2 {
				if t1/t2 >= 2 {
					c += int(Log2(float64((t1 - 1) / t2)))
				}
			} else {
				if t2/t1 >= 2 {
					c += int(Log2(float64((t2 - 1) / t1)))
				}
			}
		}
		Fprintln(out, c)
		line = make([]int, 0)
		c = 0
	}
}

package main

import "fmt"

func main() {
	N := 0
	fmt.Scan(&N)
	for I := 0; I < N; I++ {
		s := 0
		n := 0
		fmt.Scan(&n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			t := 0
			fmt.Scan(&t)
			a[i] = t
		}
		for i := 0; i < n-1; i++ {
			if a[i] > a[i+1]*2 {
				t := a[i+1]
				for {
					if t*2 >= a[i] {
						break
					}
					t *= 2
					s++
				}
			}
			if a[i+1] > a[i]*2 {
				t := a[i]
				for {
					if t*2 >= a[i+1] {
						break
					}
					t *= 2
					s++
				}
			}
		}
		fmt.Println(s)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		a := sint64s(n)
		printf("%d\n", sol(n, a))
	}
}

func sol(n int64, a []int64) int64 {
	ret := int64(0)
	for i := range a {
		if i == len(a)-1 {
			break
		}
		l := a[i]
		r := a[i+1]
		ret += diff(l, r)
	}
	return ret
}

func diff(l, r int64) int64 {
	if l > r {
		l, r = r, l
	}
	ret := int64(0)
	for {
		l *= 2
		if l >= r {
			break
		}
		ret++
	}
	return ret
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := getIntln(reader)
		var res, a, b int
		for i := 1; i < n; i++ {
			if A[i] > A[i-1] {
				a, b = A[i], A[i-1]
			} else {
				a, b = A[i-1], A[i]
			}
			y := math.Log2(float64(a) / float64(b))
			if y-math.Floor(y) > 0.025 {
				y = math.Ceil(y)
			}
			res += int(y) - 1
		}
		writer.WriteString(fmt.Sprintln(res))
	}

	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := getIntln(reader)
		var res, a, b int
		for i := 1; i < n; i++ {
			if A[i] > A[i-1] {
				a, b = A[i], A[i-1]
			} else {
				a, b = A[i-1], A[i]
			}
			y := math.Log2(float64(a) / float64(b))
			if y-math.Floor(y) > 0.01 {
				y = math.Ceil(y)
			}
			res += int(y) - 1
		}
		writer.WriteString(fmt.Sprintln(res))
	}

	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := getIntln(reader)
		var res, a, b int
		for i := 1; i < n; i++ {
			if A[i] > A[i-1] {
				a, b = A[i], A[i-1]
			} else {
				a, b = A[i-1], A[i]
			}
			res += int(math.Ceil(math.Log2(float64(a)/float64(b)))) - 1
		}
		writer.WriteString(fmt.Sprintln(res))
	}

	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import (
	"fmt"
	"math"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		ans := 0
		arr := make([]int, n+1)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
			if j > 0 {
				prev := arr[j-1]
				cur := arr[j]
				r := math.Abs(math.Log2(float64(prev)) - math.Log2(float64(cur)))
				if math.Floor(r) == r {
					if int(math.Floor(r)) > 1 {
						ans += int(math.Floor(r)) - 1
					}
				} else {
					ans += int(math.Floor(r))
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"math"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		ans := 0
		arr := make([]int, n+1)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
			if j > 0 {
				prev := arr[j-1]
				cur := arr[j]
				r := math.Abs(math.Log2(float64(prev)) - math.Log2(float64(cur)))
				if math.Floor(r) == r && int(math.Floor(r)) > 1 {
					ans += int(math.Floor(r)) - 1
				} else {
					ans += int(math.Floor(r))
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"math"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		ans := 0
		arr := make([]int, n+1)
		for j := 0; j < n; j++ {
			fmt.Scan(&arr[j])
			if j > 0 {
				prev := arr[j-1]
				cur := arr[j]
				r := math.Abs(math.Log2(float64(prev)) - math.Log2(float64(cur)))
				if math.Floor(r) == r {
					ans += int(math.Floor(r)) - 1
				} else {
					ans += int(math.Floor(r))
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

type Pair struct {
	a, b int64
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	t := getI()
	dp := make(map[Pair]int64)

	forEach(t, func(i int64) {
		len := getI()
		nums := getInts(len)
		res := int64(0)
		forEach(len-1, func(j int64) {
			mi := min(nums[j], nums[j+1])
			ma := max(nums[j], nums[j+1])

			p := Pair{mi, ma}
			if val, ok := dp[p]; ok {
				res += val
			} else {
				for mi*2 < ma {
					res++
					mi *= 2
				}
				dp[p] = res
			}
		})
		out(res)
	})
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

type Pair struct {
	a, b int64
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	t := getI()
	dp := make(map[Pair]int64)

	forEach(t, func(i int64) {
		len := getI()
		nums := getInts(len)
		res := int64(0)
		forEach(len-1, func(j int64) {
			mi := min(nums[j], nums[j+1])
			ma := max(nums[j], nums[j+1])

			p := Pair{mi, ma}
			if val, ok := dp[p]; ok {
				res = val
			} else {
				for mi*2 < ma {
					res++
					mi *= 2
				}
				dp[p] = res
			}
		})
		out(res)
	})
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

func MIN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		// // STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		count := 0
		for i := 1; i < n; i++ {
			t := float64(MAX(ARRAY[i], ARRAY[i-1]) / MIN(ARRAY[i], ARRAY[i-1]))
			if t > 2 {
				count = count + 1
			}
			if t > 4 {
				count = count + 1
			}
			if t > 8 {
				count = count + 1
			}
			if t > 16 {
				count = count + 1
			}
			if t > 32 {
				count = count + 1
			}

		}
		fmt.Println(count)

	}

}

package main

import "fmt"

func missingNum(proportion float32) (missing int16) {
	var powerOfTwo int16 = 2
	missing = 0
	for float32(powerOfTwo) < proportion {
		powerOfTwo = (powerOfTwo << 1)
		missing++
	}
	return
}

func main() {
	var t uint16
	fmt.Scan(&t)
	var n int8
	var arr []float32
	var tmp float32
	var res int16
	var proportion float32

	for i := uint16(0); i < t; i++ {
		fmt.Scan(&n)
		for j := int8(0); j < n; j++ {
			fmt.Scan(&tmp)
			arr = append(arr, tmp)
			if j > 0 {
				proportion = arr[j-1] / arr[j]
				if proportion < 0.5 {
					proportion = 1 / proportion
				}
				if proportion > 2 {
					res += missingNum(proportion)
				}
			}
		}
	}

	fmt.Println(res)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var T, a, b, n int
	fmt.Scan(&T)
	var count int = 0
	for t := 0; t < T; t++ {
		fmt.Scan(&n, &a)
		for i := 1; i < n; i++ {
			fmt.Scan(&b)
			var x, y float64 = math.Min(float64(a), float64(b)), math.Max(float64(a), float64(b))
			for x * 2 < y {
				x *= 2
				count++
			}
			a = b
		}
	}
	fmt.Println(count)
}

package main

import (
    "bufio"
    "io"
    "os"
    . "fmt"
    . "math"
)
var input io.Reader = bufio.NewReader(os.Stdin)
func main() {
    var t int
    Fscan(input, &t)
    for i := 0; i < t; i++ {
        var n int
        Fscan(input, &n)
        a := make([]float64, n)

        ans := 0
        for i:= 0; i < n; i++ {
            Fscan(input, &a[i])
            if i != 0 {
                ans += int(Ceil(Log2(Max(a[i-1], a[i]) /
                        Min(a[i-1], a[i])))) -1
            }
        }
        Println(ans)
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func f(a []int) int {
	max := func(a, b int) int {
		if a >= b {
			return a
		}
		return b
	}
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}

	var res int
	for i := 0; i < len(a)-1; i++ {
		ma := max(a[i], a[i+1])
		mi := min(a[i], a[i+1])
		for ; mi*2 < ma; res++ {
			mi *= 2
		}

	}
	return res
}
func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; n > 0; n, i = n-1, i+1 {
			fmt.Fscan(in, &a[i])
		}
		println(f(a))
	}
}