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$).


-----Input-----

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$).


-----Output-----

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


-----Examples-----

Input
6
4
4 2 10 1
2
1 3
2
6 1
3
1 4 2
5
1 2 3 4 3
12
4 31 25 50 30 20 34 46 42 16 15 16
Output
5
1
2
1
0
3


-----Note-----

The 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.

Difficulty: EASY

Solutions:
n = int(input())
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	c = 0
	for j in range(x - 1):
		b = 0
		y = max(a[j], a[j + 1])
		z = min(a[j], a[j + 1])
		while 2 * z < y:
			z = z * 2
			b = b + 1
		c = c + b
	print(c)


import math
for t in range(int(input())):
	n = int(input())
	arr = [int(k) for k in input().split()]
	ans = 0
	for i in range(n - 1):
		if max(arr[i], arr[i + 1]) > 2 * min(arr[i], arr[i + 1]):
			ans += int(math.log((max(arr[i], arr[i + 1]) - 1) / min(arr[i], arr[i + 1]), 2))
	print(ans)


from sys import stdin
import math
from collections import Counter

def arrayinput():
	return [int(x) for x in stdin.readline().split()]

def integerinput():
	return int(stdin.readline())

def stringinput():
	return stdin.readline()

def twonumberinput():
	return map(int, stdin.readline().split())

def stringrarray():
	return stdin.readline().split(' ')

def Convert(string):
	list1 = []
	list1[:0] = string
	return list1

def binary(arr, x):
	l = 0
	u = len(arr)
	while l <= u:
		mid = (l + u) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			u = mid - 1
		else:
			l = mid + 1
	return -1
for i in range(integerinput()):
	integerinput()
	a = arrayinput()
	count = 0
	for i in range(len(a)):
		if i == len(a) - 1:
			break
		if max(a[i + 1], a[i]) <= 2 * min(a[i + 1], a[i]):
			continue
		else:
			if a[i + 1] > a[i]:
				x = a[i]
				while x < math.ceil(a[i + 1] / 2):
					x = x * 2
					count += 1
			if a[i + 1] < a[i]:
				x = a[i]
				while x > 2 * a[i + 1]:
					x = math.ceil(x / 2)
					count = count + 1
	print(count)


a = int(input())
for i in range(a):
	i = 0
	s = int(input())
	lis = list(map(int, input().split()))
	for h in range(s - 1):
		p = max(lis[h], lis[h + 1]) / min(lis[h], lis[h + 1])
		while p > 2:
			p = p / 2
			i += 1
	print(i)


t = int(input())
list_of_lists = []
answers = [0] * t
temp_list = []
for i in range(t):
	length = int(input())
	ary = [int(j) for j in input().split()]
	list_of_lists.append(ary)
for (j, l) in enumerate(list_of_lists):
	i = 0
	temp_list = []
	temp_list.append(l[i])
	while i < len(l) - 1:
		if max(temp_list[-1], l[i + 1]) / min(temp_list[-1], l[i + 1]) <= 2:
			temp_list.append(l[i + 1])
			i += 1
		elif temp_list[-1] > l[i + 1]:
			if temp_list[-1] % 2 == 0:
				temp_list.append(temp_list[-1] // 2)
			else:
				temp_list.append(max(temp_list[-1] // 2 + 1, 2))
		else:
			temp_list.append(2 * temp_list[-1])
	answers[j] = len(temp_list) - len(l)
for a in answers:
	print(a)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = 0
	for i in range(1, n):
		(mn, mx) = sorted([a[i - 1], a[i]])
		if mx / mn > 2:
			while mx / mn > 2:
				mn *= 2
				ans += 1
	print(ans)


import math

def solve(a):
	x = 0
	for (n1, n2) in zip(a, a[1:]):
		if n1 > n2:
			(n1, n2) = (n2, n1)
		while True:
			n1 *= 2
			if n1 >= n2:
				break
			x += 1
	return x
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a))


import math
t = int(input())

def check():
	return max(a[i], a[i + 1]) > 2 * min(a[i], a[i + 1])
res = []
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	i = 0
	c = 0
	while i < len(a) - 1:
		if check():
			a.insert(i + 1, math.ceil(max(a[i], a[i + 1]) / 2))
			c += 1
		else:
			i += 1
	res.append(c)
for i in res:
	print(i)


def Densar(Min, Max):
	Cont = 0
	while Max > Min:
		Min = Min * 2
		Cont = Cont + 1
	return Cont - 1
Test = int(input())
for T in range(Test):
	N = int(input())
	L = list(map(int, input().split()))
	Suma = 0
	for K in range(N - 1):
		if L[K] > L[K + 1]:
			Max = L[K]
			Min = L[K + 1]
		else:
			Max = L[K + 1]
			Min = L[K]
		if Max / Min > 2:
			Cont = Densar(Min, Max)
			Suma = Suma + Cont
	print(Suma)


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
import math
t = 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		ratio = max(a[i - 1], a[i]) / min(a[i - 1], a[i])
		(lar, sma) = (max(a[i - 1], a[i]), min(a[i - 1], a[i]))
		if max(a[i - 1], a[i]) / min(a[i - 1], a[i]) > 2:
			while sma * 2 < lar:
				sma *= 2
				ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = 0
	for i in range(n - 1):
		if max(a[i], a[i + 1]) / min(a[i], a[i + 1]) > 2:
			maxx = max(a[i], a[i + 1])
			minn = min(a[i], a[i + 1])
			while minn < maxx:
				ans += 1
				minn *= 2
			ans -= 1
	print(ans)


from math import log
t = int(input())
for m in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(n - 1):
		(x, y) = (max(a[i], a[i + 1]), min(a[i], a[i + 1]))
		div = x / y
		while div > 2:
			y *= 2
			count += 1
			div = x / y
	print(count)


def solve(n, a):
	ans = 0
	for i in range(0, n - 1):
		if a[i + 1] / a[i] > 2:
			k = a[i]
			while k * 2 < a[i + 1]:
				k *= 2
				ans += 1
		if a[i] / a[i + 1] > 2:
			k = a[i + 1]
			while k * 2 < a[i]:
				k *= 2
				ans += 1
	return ans
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


from math import ceil
import os
import sys
from io import BytesIO, IOBase

def arr_input():
	return list(map(int, input().split()))

def mul_input():
	return map(int, input().split())

def int_inp():
	return int(input())

def solution():
	n = int_inp()
	a = arr_input()
	ans = 0
	for i in range(1, n):
		x = max(a[i], a[i - 1])
		y = min(a[i], a[i - 1])
		if x / y <= 2:
			continue
		else:
			while x / y > 2:
				ans += 1
				x = x / 2
	print(ans)
	return

def main():
	testcases = 1
	testcases = int(input())
	for _ in range(testcases):
		solution()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(0, n - 1):
		a = min(arr[i], arr[i + 1])
		b = max(arr[i], arr[i + 1])
		while a * 2 < b:
			ans += 1
			a *= 2
	print(ans)
	t -= 1


ssi = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	l = list(ssi())
	i = 0
	ans = 0
	while i < n - 1:
		(s, b) = sorted(l[i:i + 2])
		while 2 * s < b:
			s <<= 1
			ans += 1
		i += 1
	print(ans)


from math import log2
for w in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	t = 0
	for j in range(n - 1):
		x = max(a[j], a[j + 1])
		y = min(a[j], a[j + 1])
		if x > 2 * y:
			h = log2(x / y)
			t += int(h) - 1 if h == int(h) else int(h)
	print(t)


def dense_array():
	t = int(input())
	for test in range(t):
		len_arr = int(input())
		n = input().split(' ')
		arr = []
		for inp in n:
			inp = int(inp)
			arr.append(inp)
		count = 0
		for i in range(len(arr) - 1):
			max_adj = max(arr[i], arr[i + 1])
			min_adj = min(arr[i], arr[i + 1])
			while min_adj * 2 < max_adj:
				min_adj = min_adj * 2
				count += 1
		print(count)
dense_array()


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	c = 0
	for itr in range(1, n):
		(prev, next) = (arr[itr - 1], arr[itr])
		(mini, maxi) = (min(prev, next), max(prev, next))
		if maxi / mini > 2:
			while mini < maxi / 2:
				c += 1
				mini *= 2
	print(c)


import sys
input = sys.stdin.readline
output = sys.stdout.write

def main():
	tests = int(input().rstrip())
	for i in range(tests):
		length_ = int(input().rstrip())
		nums_ = list(map(int, input().rstrip().split()))
		needed = 0
		for j in range(length_ - 1):
			a = nums_[j]
			b = nums_[j + 1]
			if a > b:
				max_ = a
				min_ = b
			elif b > a:
				max_ = b
				min_ = a
			else:
				continue
			state = True
			temp = max_ / min_
			while state:
				if temp > 2:
					needed += 1
					temp /= 2
				else:
					state = False
		output(str(needed))
		output('\n')
main()


import math
num = 0
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(2500):
		if i + 2 > len(a):
			break
		for x in range(25):
			if a[i] > a[i + 1] and a[i] / a[i + 1] > 2:
				a.insert(i + 1, math.ceil(a[i] / 2))
				num += 1
			elif a[i + 1] > a[i] and a[i + 1] / a[i] > 2:
				a.insert(i + 1, math.ceil(a[i + 1] / 2))
				num += 1
	print(num)
	num = 0


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(n - 1):
		M = max(a[i + 1], a[i])
		m = min(a[i + 1], a[i])
		while M / m > 2:
			m = 2 * m
			count += 1
	print(count)


def get_dense_list(length: int, arr: list):
	change = 0
	for i in range(length):
		if i == length - 1:
			break
		ma = max(arr[i], arr[i + 1])
		mi = min(arr[i], arr[i + 1])
		while ma / mi > 2:
			mi *= 2
			change += 1
	return change
for _ in range(int(input())):
	print(get_dense_list(int(input()), [int(x) for x in input().split()]))


t = int(input())
o = 0
while o != t:
	o += 1
	a = int(input())
	n = list(map(int, input().split()))
	b = 0
	for i in range(1, a):
		if n[i - 1] * 2 < n[i]:
			g = n[i - 1]
			while g * 2 < n[i]:
				g = g * 2
				b += 1
		if n[i] * 2 < n[i - 1]:
			g = n[i]
			while g * 2 < n[i - 1]:
				g = g * 2
				b += 1
	print(b)


import math
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	for i in range(len(l) - 1):
		if max(l[i], l[i + 1]) / min(l[i], l[i + 1]) > 2:
			count = count + math.ceil(math.log(max(l[i], l[i + 1]) / min(l[i], l[i + 1]), 2)) - 1
	print(count)


def solve(n, xs):
	additions = 0
	for (i, x) in enumerate(xs[:-1]):
		y = xs[i + 1]
		(smaller, bigger) = (min(x, y), max(x, y))
		while 2 * smaller < bigger:
			smaller *= 2
			additions += 1
	return additions

def main():
	for _ in range(int(input())):
		n = int(input())
		xs = [int(x) for x in input().split()]
		ans = solve(n, xs)
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	i = 0
	ans = 0
	for i in range(n - 1):
		a = min(arr[i], arr[i + 1])
		b = max(arr[i], arr[i + 1])
		while 2 * a < b:
			ans += 1
			a *= 2
	print(ans)


a = int(input())
for i in range(a):
	p = 0
	c = int(input())
	b = [int(i) for i in input().split()]
	for i in range(c - 1):
		if max(b[i], b[i + 1]) > min(b[i], b[i + 1]) * 2:
			o = 2
			while max(b[i], b[i + 1]) / min(b[i], b[i + 1]) > o:
				o = o * 2
				p = p + 1
	print(p)


for _ in range(int(input())):
	k = 0
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n - 1):
		mi = min(l[i], l[i + 1])
		ma = max(l[i], l[i + 1])
		if ma / mi > 2:
			while True:
				mi = mi * 2
				if mi < ma:
					k += 1
				else:
					break
	print(k)


t = int(input())
for i in range(t):
	n = int(input())
	l = input().split(' ')
	for j in range(n):
		l[j] = int(l[j])
	p = 0
	for j in range(n - 1):
		if l[j] > l[j + 1]:
			a = l[j]
			b = l[j + 1]
		else:
			a = l[j + 1]
			b = l[j]
		if a % b == 0:
			a = a // b
			if a > 2:
				if a > 4:
					if a > 8:
						if a > 16:
							if a > 32:
								p += 5
							else:
								p += 4
						else:
							p += 3
					else:
						p += 2
				else:
					p += 1
		else:
			a = a // b
			if a >= 2:
				if a >= 4:
					if a >= 8:
						if a >= 16:
							if a >= 32:
								p += 5
							else:
								p += 4
						else:
							p += 3
					else:
						p += 2
				else:
					p += 1
	print(p)


from math import log
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = 0
	for j in range(n - 1):
		maxi = max(arr[j], arr[j + 1])
		mini = min(arr[j], arr[j + 1])
		cnt += int(log(maxi / mini - 0.01, 2))
	print(cnt)


import copy
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	gg = 0
	for i in range(len(a) - 1):
		h = max(a[i], a[i + 1])
		m = min(a[i], a[i + 1])
		if h / m > 2:
			t = copy.deepcopy(m)
			while h / t > 2:
				gg += 1
				t = 2 * t
	print(gg)


t = int(input())

def cal_num(n, t):
	if n == t:
		return 0
	cnt = 0
	if n == 1:
		n = 2
		cnt += 1
	while n < t:
		n *= 2
		cnt += 1
	return cnt - 1
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans = 0
	for i in range(1, n):
		ans += cal_num(min(arr[i], arr[i - 1]), max(arr[i], arr[i - 1]))
	print(ans)


tc = int(input())
lst = []
for cs in range(0, tc):
	res = 0
	n = int(input())
	line = input()
	num = list(map(int, line.split()))
	for i in range(1, n):
		x = min(num[i - 1], num[i])
		y = max(num[i - 1], num[i])
		while x * 2 < y:
			x *= 2
			res = res + 1
	print(f'{res}')


from math import log2, floor, ceil
t = int(input())
while t != 0:
	changes = 0
	t -= 1
	n = int(input())
	numList = [int(x) for x in input().split()]
	for i in range(len(numList) - 1):
		pair = [numList[i], numList[i + 1]]
		dense = True if max(pair) / min(pair) <= 2 else False
		if not dense:
			ratio = max(pair) / min(pair)
			x = ceil(log2(ratio)) - 1
			changes += x
	print(changes)


def inl():
	return [int(i) for i in input().split()]

def inp():
	return int(input())
for _ in range(inp()):
	n = inp()
	a = inl()
	cnt = 0
	for i in range(1, n):
		x = min(a[i], a[i - 1])
		y = max(a[i], a[i - 1])
		while 2 * x < y:
			x = x * 2
			cnt += 1
	print(cnt)


tests = int(input())
c = [2 ** i for i in range(1, 8)]
for _ in range(tests):
	m = int(input())
	n = list(map(int, input().split()))
	res = 0
	for i in range(1, m):
		(x, y) = (n[i - 1], n[i])
		if x == y or y < x <= 2 * y or x < y <= 2 * x:
			continue
		if x > 2 * y:
			t = x // y + (1 if x % y else 0)
		else:
			t = y // x + (1 if y % x else 0)
		for cc in c:
			if cc < t:
				res += 1
			else:
				break
	print(res)


from math import sqrt
import operator
import sys
inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def check_seq(a_list):
	res = 0
	r = a_list[0]
	for i in range(1, len(a_list)):
		l = r
		r = a_list[i]
		max_el = max(l, r)
		min_el = min(l, r)
		if max_el / min_el <= 2.0:
			continue
		while max_el / min_el > 2.0:
			if max_el % 2 == 1:
				max_el = max_el // 2 + 1
			else:
				max_el = max_el // 2
			res += 1
	return res

def main():
	cnt = read_one_int()
	for _ in range(cnt):
		n = read_one_int()
		a_list = read_list_of_ints()
		res = check_seq(a_list)
		print(res)
main()


def dense(a):
	i = 0
	t = 0
	while i < len(a) - 1:
		if a[i] < a[i + 1]:
			if a[i + 1] / a[i] > 2:
				x = 2 * a[i]
				t += 1
				while a[i + 1] / x > 2:
					x = x * 2
					t += 1
		elif a[i] / a[i + 1] > 2:
			x = 2 * a[i + 1]
			t += 1
			while a[i] / x > 2:
				x = x * 2
				t += 1
		i += 1
	print(t)
prim = int(input())
while prim > 0:
	n = int(input())
	a = input().split(' ')
	a = [int(i) for i in a]
	dense(a)
	prim -= 1


def add(Min, Max):
	c = 0
	while Min * 2 < Max:
		Min *= 2
		c += 1
	return c
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n - 1):
		if a[i] < a[i + 1]:
			Min = a[i]
			Max = a[i + 1]
		elif a[i] > a[i + 1]:
			Min = a[i + 1]
			Max = a[i]
		else:
			continue
		if Max > 2 * Min:
			c += add(Min, Max)
	print(c)
	t -= 1


def suspision(n, arr):
	count = 0
	prev = arr[0]
	for i in range(len(arr)):
		if arr[i] / prev <= 2 and prev / arr[i] <= 2:
			prev = arr[i]
		elif arr[i] / prev >= 2:
			temp = 2 * prev
			while temp < arr[i]:
				temp *= 2
				count += 1
			prev = arr[i]
		elif prev / arr[i] >= 2:
			temp = 2 * arr[i]
			while temp < prev:
				temp *= 2
				count += 1
			prev = arr[i]
	return count
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	result = suspision(n, arr)
	print(result)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from collections import deque as dq
from math import ceil, floor, sqrt, pow, factorial
for _ in range(N()):
	n = N()
	l = RLL()
	c = 0
	for i in range(1, n):
		if max(l[i], l[i - 1]) <= 2 * min(l[i], l[i - 1]):
			continue
		else:
			a = max(l[i], l[i - 1])
			b = min(l[i], l[i - 1])
			while a > 2 * b:
				b = 2 * b
				c += 1
	print(c)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(n - 1):
		d = max(a[i + 1], a[i]) / min(a[i + 1], a[i])
		if d > 2:
			cnt += math.ceil(math.log(d, 2)) - 1
	print(cnt)


def count(a, b):
	c = 0
	while a * 2 < b:
		a *= 2
		c += 1
	while b * 2 < a:
		b *= 2
		c += 1
	return c
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(len(a) - 1):
		ans += count(a[i], a[i + 1])
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(n - 1):
		if 2 * a[i] < a[i + 1]:
			while 2 * a[i] < a[i + 1]:
				a[i] *= 2
				cnt += 1
		elif a[i] > 2 * a[i + 1]:
			while a[i] > 2 * a[i + 1]:
				a[i] /= 2
				cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	c = 0
	for i in range(1, n):
		m = max(arr[i], arr[i - 1])
		s = min(arr[i], arr[i - 1])
		if m / s > 2:
			while m / s > 2:
				s = s * 2
				c += 1
	print(c)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	res = 0
	for i in range(n - 1):
		ma = max(A[i], A[i + 1])
		mi = min(A[i], A[i + 1])
		if ma <= 2 * mi:
			continue
		while mi * 2 < ma:
			mi *= 2
			res += 1
	print(res)

def resolve():
	t = int(input())
	for _ in range(t):
		solve()
resolve()


import math

def f():
	c = 0
	n = int(input(''))
	l = list(map(int, input('').split(' ')))
	l.append(l[n - 1])
	for i in range(n):
		if l[i + 1] > 2 * l[i]:
			j = l[i]
			while 1:
				if 2 * j >= l[i + 1]:
					break
				else:
					c = c + 1
					j = j * 2
		elif l[i] > 2 * l[i + 1]:
			j = l[i + 1]
			while 1:
				if 2 * j >= l[i]:
					break
				else:
					c = c + 1
					j = j * 2
	print(c)
n = int(input(''))
for i in range(n):
	f()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		max_a = max(a[i], a[i + 1])
		min_a = min(a[i], a[i + 1])
		if max_a <= min_a * 2:
			continue
		while min_a * 2 < max_a:
			min_a *= 2
			ans += 1
	print(ans)


import sys
from itertools import *
from math import *
from sys import stdin, stdout

def ans(n, lst):
	(left, right) = (0, len(lst) - 1)
	c = 0
	while left < right:
		maximum = max(lst[left], lst[left + 1])
		minimum = min(lst[left], lst[left + 1])
		while maximum > minimum * 2:
			c += 1
			minimum *= 2
		left += 1
	print(c)
for i in range(int(stdin.readline())):
	n = int(stdin.readline())
	lst = list(map(int, stdin.readline().split()))
	ans(n, lst)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(1, n):
		(x, y) = (a[i - 1], a[i])
		if x < y:
			(x, y) = (y, x)
		while x > y * 2:
			y *= 2
			c += 1
	print(c)


from math import *
from statistics import mode
from functools import reduce
from sys import stdin

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1

def graph(vertex):
	return [[] for i in range(vertex + 1)]

def lcm(a, b):
	return a * b // gcd(a, b)

def most_common(List):
	return mode(List)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def prime_factors(n):
	(i, factors) = (2, [])
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def kadane(a, size):
	max_so_far = curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def isPowerOf2(x):
	return x and (not x & x - 1)

def isPerfectSquare(n):
	return pow(floor(sqrt(n)), 2) == n

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1
for t in range(int(input())):
	N = int(input())
	ar = list(map(int, input().split()))
	count = 0
	for i in range(len(ar) - 1):
		(mx, mn) = (max(ar[i + 1], ar[i]), min(ar[i + 1], ar[i]))
		while mx > 2 * mn:
			mn *= 2
			count += 1
	print(count)


def steps_to_dense(a, n):
	k = 0
	for i in range(1, n):
		mx = max(a[i - 1], a[i])
		mn = min(a[i - 1], a[i])
		while 2 * mn < mx:
			mn = 2 * mn
			k += 1
	return k
t = int(input())
for it in range(t):
	n = int(input())
	a = [int(tmp) for tmp in input().split()]
	print(steps_to_dense(a, n))


from sys import stdin, stdout
input = stdin.readline
from random import sample
t = int(input())
from collections import Counter
from math import sqrt, ceil

def ps(n):
	cp = 0
	while n % 2 == 0:
		n = n // 2
		cp += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		while n % ps == 0:
			n = n // ps
			cp += 1
	if n != 1:
		return False
	return True

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qrr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(slr - dpr + 1, slr + 1):
		qlr = qlr * ip % mod
	for ij in range(1, dpr + 1):
		qs = qs * ip % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
for jj in range(t):
	ll = int(input())
	n = ll
	arr = [int(x) for x in input().strip().split()]
	pp = 0
	for ip in range(n - 1):
		iss = max(arr[ip], arr[ip + 1])
		ra = min(arr[ip], arr[ip + 1])
		cc = 0
		while ceil(iss / ra) > 2:
			iss = ceil(iss / 2)
			cc += 1
		pp += cc
	print(pp)


import math
import sys
import collections
import bisect
import heapq
testcases = int(sys.stdin.readline())
for _ in range(testcases):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	res = 0
	for i in range(1, len(arr)):
		if abs(arr[i] - arr[i - 1]) > min(arr[i], arr[i - 1]):
			x = math.ceil(math.log(max(arr[i], arr[i - 1]) / min(arr[i], arr[i - 1]), 2))
			res += x - 1
	print(res)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	l = len(a)
	number_to_add = 0
	for i in range(l - 1):
		if a[i] > 2 * a[i + 1]:
			number_to_add += abs(math.ceil(math.log(int(a[i]) / int(a[i + 1]), 2)) - 1)
		elif a[i + 1] > 2 * a[i]:
			number_to_add += abs(math.ceil(math.log(int(a[i + 1]) / int(a[i]), 2)) - 1)
		else:
			continue
	print(number_to_add)


def main():
	for _ in range(int(input())):
		input()
		it = map(float, input().split())
		(a, r) = (next(it), 0)
		for b in it:
			while a * 2.0 < b:
				a *= 2.0
				r += 1
			while a * 0.5 > b:
				a *= 0.5
				r += 1
			a = b
		print(r)
main()


def solve(A, n):
	nums = 0
	for i in range(n - 1):
		h = max(A[i], A[i + 1])
		l = min(A[i], A[i + 1])
		r = h / l
		if r <= 2:
			continue
		else:
			while l * 2 < h:
				l *= 2
				nums += 1
	return nums
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	ans = solve(A, n)
	print(ans)


for t in range(int(input())):
	n = int(input())
	mas = list(map(int, input().split()))
	otv = 0
	for i in range(n - 1):
		a = min(mas[i], mas[i + 1])
		b = max(mas[i], mas[i + 1])
		while a * 2 < b:
			a *= 2
			otv += 1
	print(otv)


import math
t = int(input())
natija = []
for i in range(t):
	n = int(input())
	satr = input()
	ruyhat = satr.split(' ')
	umumiy_son = 0
	for i in range(n):
		ruyhat[i] = int(ruyhat[i])
	for i in range(n - 1):
		farq = max(ruyhat[i], ruyhat[i + 1]) / min(ruyhat[i], ruyhat[i + 1])
		if farq > 2:
			x = math.floor(math.log2(farq))
			if 2 ** x == farq:
				umumiy_son += x - 1
			else:
				umumiy_son += x
	natija.append(umumiy_son)
for i in range(t):
	print(natija[i])


def func():
	n = int(input())
	lst = list(map(int, input().split()))
	cnt = 0
	for i in range(n - 1):
		maxV = max(lst[i], lst[i + 1])
		minV = min(lst[i], lst[i + 1])
		while minV * 2 < maxV:
			minV *= 2
			cnt += 1
	print(cnt)

def main():
	for i in range(int(input())):
		func()
main()


import math

def countins(l, n):
	count = 0
	for i in range(n - 1):
		a = max(l[i], l[i + 1])
		b = min(l[i], l[i + 1])
		if l[i] > l[i + 1]:
			while a / b > 2:
				a = math.ceil(a / 2)
				count += 1
		if l[i] < l[i + 1]:
			while a / b > 2:
				b = b * 2
				count += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	result = countins(l, n)
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	r = 0
	for i in range(len(arr) - 1):
		(x, y) = (arr[i], arr[i + 1])
		if x > y:
			(x, y) = (y, x)
		while 2 * x < y:
			x *= 2
			r += 1
	print(r)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
	n = int(input())
	a = lnii()
	inx = 0
	while inx < len(a) - 1:
		a1 = a[inx]
		a2 = a[inx + 1]
		if a1 * 2 < a2:
			a.insert(inx + 1, a1 * 2)
		elif a2 * 2 < a1:
			a.insert(inx + 1, (a1 + 2 - 1) // 2)
		inx += 1
	ans = len(a) - n
	print(ans)


import math
from collections import defaultdict

def find(mini, maxi):
	x = 2 * mini
	c = 1
	while maxi > 2 * x:
		x = 2 * x
		c += 1
	return c
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	for i in range(n - 1):
		mini = min(l[i], l[i + 1])
		maxi = max(l[i], l[i + 1])
		if maxi > 2 * mini:
			cnt += find(mini, maxi)
	print(cnt)


from math import ceil, log2
for t in range(int(input())):
	array_len = int(input())
	array = list(map(int, input().split()))
	numbers_to_insert = 0
	for i in range(1, array_len):
		ratio = max(array[i - 1], array[i]) / min(array[i - 1], array[i])
		if ratio > 2:
			numbers_to_insert += ceil(log2(ratio)) - 1
	print(numbers_to_insert)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		if l[i] > l[i + 1]:
			ptr = l[i + 1]
			while ptr * 2 < l[i]:
				ptr *= 2
				ans += 1
		else:
			ptr = l[i]
			while ptr * 2 < l[i + 1]:
				ptr *= 2
				ans += 1
	print(ans)


def solution():
	n = int(input())
	for _ in range(n):
		_ = input()
		a = list(map(int, input().split()))
		i = 1
		curr = a[0]
		res = 0
		while i < len(a):
			if max(curr, a[i]) / min(curr, a[i]) <= 2:
				curr = a[i]
				i += 1
			else:
				if a[i] > curr:
					curr *= 2
				elif curr % 2 == 0:
					curr //= 2
				else:
					curr //= 2
					curr += 1
				res += 1
		print(res)
solution()


t = int(input())
for i in range(t):
	ans = 0
	n = int(input())
	l = list(map(int, input().split()))
	for j in range(len(l) - 1):
		u = l[j]
		v = l[j + 1]
		if u > v:
			u = l[j + 1]
			v = l[j]
		while 2 * u < v:
			ans += 1
			u *= 2
	print(ans)


for _ in range(int(input())):
	(n, arr, num) = (int(input()), list(map(int, input().split())), 0)
	for i in range(n - 1):
		num += len(bin(-1 - max(arr[i], arr[i + 1]) // -min(arr[i], arr[i + 1]))) - 3
	print(num)


t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	prev = list1[0]
	i = 1
	c = 0
	while i < len(list1):
		if list1[i] > prev:
			if list1[i] > 2 * prev:
				c += 1
				prev = 2 * prev
			else:
				prev = list1[i]
				i += 1
		else:
			import math
			if list1[i] * 2 < prev:
				prev = math.ceil(prev / 2)
				c += 1
			else:
				prev = list1[i]
				i += 1
	print(c)
	t -= 1


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		e1 = l[0]
		s = 0
		for i in range(1, n):
			a = max(e1, l[i])
			b = min(e1, l[i])
			while a > 2 * b:
				s += 1
				b *= 2
			e1 = l[i]
		print(s)
main()


def doit():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		t = (max(a[i + 1], a[i]) - 1) // min(a[i + 1], a[i]) + 1
		ans += len(bin(t - 1)) - 2 - 1
	print(ans)
T = int(input())
for _ in range(T):
	doit()


t = int(input())
for r in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = l[0]
	ans = 0
	for i in range(1, len(l)):
		b = l[i]
		c = min(a, b)
		d = max(a, b)
		while True:
			if c * 2 < d:
				ans += 1
				c *= 2
			else:
				break
		a = b
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	arr = list(map(int, input().split()))
	i = 0
	while i < n - 1:
		if max(arr[i], arr[i + 1]) / min(arr[i], arr[i + 1]) > 2:
			ans += 1
			n += 1
			arr.insert(i + 1, min(arr[i], arr[i + 1]) * 2)
		else:
			i += 1
	print(ans)


it = int(input())
for _ in range(it):
	n = int(input())
	arr = [int(i) for i in input().split()]
	added = 0
	for i in range(n - 1):
		min_i = min(arr[i], arr[i + 1])
		max_i = max(arr[i], arr[i + 1])
		while min_i * 2 < max_i:
			added += 1
			min_i *= 2
	print(added)


class Solution:

	def solve(self, n, arr):
		result = 0
		for i in range(n - 1):
			minn = min(arr[i], arr[i + 1])
			maxx = max(arr[i], arr[i + 1])
			while maxx / minn > 2.0:
				minn = minn * 2
				result += 1
		return result
sol = Solution()
tests = int(input())
results = []
for test in range(tests):
	n = int(input())
	arr = list(map(int, input().split()))
	result = sol.solve(n, arr)
	results.append(result)
for result in results:
	print(result)


def f(n, arr):
	ans = 0
	for i in range(n - 1):
		if arr[i] > arr[i + 1] and arr[i + 1] * 2 < arr[i]:
			k = arr[i + 1]
			while k * 2 < arr[i]:
				k *= 2
				ans += 1
		elif arr[i + 1] > arr[i] and arr[i] * 2 < arr[i + 1]:
			k = arr[i]
			while k * 2 < arr[i + 1]:
				k *= 2
				ans += 1
	return ans
for _ in range(int(input())):
	nn = int(input())
	v = [int(x) for x in input().split()]
	print(f(nn, v))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	ret = 0
	a = list(map(int, input().split()))
	for i in range(n - 1):
		temp = math.ceil(math.log2(max(a[i + 1] / a[i], a[i] / a[i + 1]))) - 1
		ret = ret + max(0, temp)
	print(ret)


def solve(n, a):
	count = 0
	for i in range(n - 1):
		xmax = max(a[i], a[i + 1])
		xmin = min(a[i], a[i + 1])
		while 2 * xmin < xmax:
			xmin *= 2
			count += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


for _ in range(int(input())):
	k = 0
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n - 1):
		mi = min(l[i], l[i + 1])
		ma = max(l[i], l[i + 1])
		while mi * 2 < ma:
			k += 1
			mi = mi * 2
	print(k)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	for i in range(1, n):
		mx = max(arr[i], arr[i - 1])
		mn = min(arr[i], arr[i - 1])
		while mx > 2 * mn:
			count += 1
			mn *= 2
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	j = 0
	for i in range(n - 1):
		q = min(a[i], a[i + 1])
		w = max(a[i], a[i + 1])
		while q * 2 < w:
			j += 1
			q *= 2
	print(j)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	cnt = 0
	for i in range(1, n):
		density = max(L[i], L[i - 1]) / min(L[i], L[i - 1])
		if density > 2:
			while density > 2:
				density /= 2
				cnt += 1
	ans.append(cnt)
for i in range(t):
	print(ans[i])


from math import inf
from collections import *
import math, os, sys, heapq, bisect, random, threading
from functools import lru_cache, reduce
from itertools import *
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def inpu():
	return int(inp())

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())
(M, M1) = (1000000007, 998244353)

def main():
	t = inpu()
	for _ in range(t):
		n = inpu()
		a = lis()
		res = 0
		for i in range(len(a) - 1):
			x = max(a[i], a[i + 1])
			y = min(a[i], a[i + 1])
			if x / y > 2:
				while x / y > 2:
					y *= 2
					res += 1
		print(res)
main()


import sys
it = iter(sys.stdin.read().splitlines())
t = int(next(it))
while t:
	n = int(next(it))
	m = [int(x) for x in next(it).split()]
	start = m[0]
	to_add = 0
	for i in range(1, n):
		number = m[i]
		a = number if number < start else start
		b = number if number > start else start
		while 2 * a < b:
			a *= 2
			to_add += 1
		start = number
	print(to_add)
	t -= 1


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		_ = stdin.readline()
		arr = list(map(int, stdin.readline().split()))
		res = 0
		for (a, b) in zip(arr, arr[1:]):
			(a, b) = (min(a, b), max(a, b))
			while a * 2 < b:
				a *= 2
				res += 1
		stdout.write('%i\n' % res)
main()


def count1(arr, n):
	c = 0
	for i in range(n - 1):
		a = max(arr[i], arr[i + 1])
		b = min(arr[i], arr[i + 1])
		if a / b > 2:
			temp = b
			while a / temp > 2:
				c = c + 1
				temp = temp * 2
	return c
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(count1(arr, n))


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for j in range(1, n):
		c = 0
		t1 = min(arr[j - 1], arr[j])
		t2 = max(arr[j - 1], arr[j])
		while 2 * t1 < t2:
			t1 *= 2
			c += 1
		ans += c
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(n - 1):
		new = min(a[i], a[i + 1])
		if max(a[i], a[i + 1]) / min(a[i], a[i + 1]) > 2:
			count += 1
			new = new * 2
			while max(a[i], a[i + 1]) / new > 2:
				new = new * 2
				count += 1
	print(count)


import sys
import math

def isPrime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def pa(a):
	s = ''
	for i in a:
		s += str(i) + ' '
	print(s)

def Y():
	print('YES')

def N():
	print('NO')
t = int(input().strip())
for a0 in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	c = 0
	flg = 0
	for i in range(n - 1):
		a = max(l[i], l[i + 1])
		b = min(l[i], l[i + 1])
		x = 0
		d = a / b
		e = 2
		while 1:
			if b * 2 < a:
				x += 1
				b *= 2
			else:
				break
		c += x
	print(c)


GLOBALCOUNT = []

def gap_fill(x, y):
	i = 2 * y
	GLOBALCOUNT.append(1)
	while x / i > 2:
		i *= 2
		GLOBALCOUNT.append(1)
	return
t = int(input())
for _ in range(t):
	GLOBALCOUNT.clear()
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(1, len(arr)):
		if max(arr[i - 1], arr[i]) / min(arr[i - 1], arr[i]) <= 2:
			continue
		elif arr[i] > arr[i - 1]:
			gap_fill(arr[i], arr[i - 1])
		else:
			gap_fill(arr[i - 1], arr[i])
	print(len(GLOBALCOUNT))


t = int(input())
for T in range(t):
	n = int(input())
	ab = list(map(int, input().split()))
	count = 0
	for i in range(len(ab) - 1):
		a = max(ab[i], ab[i + 1])
		b = min(ab[i], ab[i + 1])
		while b * 2 < a:
			b = b * 2
			count += 1
	print(count)


def number(a, b):
	max_ = max(a, b)
	min_ = min(a, b)
	p = 0
	curr = min_
	while max_ > 2 * curr:
		p += 1
		curr *= 2
	return p
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	out = 0
	for i in range(n - 1):
		a = arr[i]
		b = arr[i + 1]
		out += number(a, b)
	print(out)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(200001)]
pp = [0] * 200001

def SieveOfEratosthenes(n=200000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = 0
	for i in range(n - 1):
		mn = min(a[i], a[i + 1])
		mx = max(a[i], a[i + 1])
		while 2 * mn < mx:
			res += 1
			mn *= 2
	print(res)


import sys
input = sys.stdin.readline

def howmany(a, b):
	count = 0
	while b > 2 * a:
		a = a * 2
		count += 1
	return count
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	ans = 0
	for i in range(n - 1):
		z = max(li[i], li[i + 1])
		y = min(li[i], li[i + 1])
		ans = ans + howmany(y, z)
	print(ans)


import math

def chk(y):
	for i in range(1, len(y)):
		if max(y[i - 1], y[i]) > min(y[i - 1], y[i]) * 2:
			return False
	else:
		return True
for _ in range(int(input())):
	x = int(input())
	y = list(map(int, input().split()))
	g = 0
	while chk(y) != True:
		for i in range(1, len(y)):
			if max(y[i - 1], y[i]) > min(y[i - 1], y[i]) * 2:
				p = max(y[i], y[i - 1])
				tp = math.ceil(p / 2)
				y.insert(i, tp)
				g += 1
				break
	print(g)


import math
t = int(input())

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		x = min(arr[i], arr[i + 1])
		y = max(arr[i], arr[i + 1])
		while y > 2 * x:
			x *= 2
			ans += 1
	print(ans)
while t:
	solve()
	t -= 1


import math

def solution(l, a):
	count = 0
	i = 0
	while i < l - 1:
		if max(a[i], a[i + 1]) / min(a[i], a[i + 1]) > 2:
			if a[i] > a[i + 1]:
				count += math.ceil(math.log(0.5 * a[i] / a[i + 1]) / math.log(2))
			else:
				count += math.ceil(math.log(0.5 * a[i + 1] / a[i]) / math.log(2))
		i += 1
	return count
result = []
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	result.append(solution(n, arr))
print(*result, sep='\n')


def ass(a, b):
	if a != b:
		print(f'Assertion error:\n{a}\n{b}')

def intline():
	return [int(item) for item in input().split()]

def line():
	return [item for item in input().split()]

def dump(lst):
	for (i, item) in enumerate(lst):
		print(i, item)

def binsearch(arr, a, b):
	m = (a + b) // 2
	if a >= b:
		return a - 1 if arr[a] == 0 else a
	return binsearch(arr, a, m - 1) if arr[m] == 0 else binsearch(arr, m + 1, b)

def f(nrs):
	res = 0
	for i in range(1, len(nrs)):
		a = nrs[i - 1]
		b = nrs[i]
		if a > b:
			(a, b) = (b, a)
		kvot = b / a
		while kvot > 2:
			res += 1
			kvot /= 2
	return res
t = intline()[0]
for i in range(t):
	n = intline()[0]
	arr = intline()
	print(f(arr))


from math import log

def getinbetween(a, b):
	if a == b:
		return 0
	big = max(a, b) - 1
	small = min(a, b)
	return int(log(big / small, 2))
for _ in range(int(input())):
	n = int(input())
	arr = (*map(int, input().split()),)
	count = 0
	for i in range(n - 1):
		count += getinbetween(arr[i], arr[i + 1])
	print(count)


k = []
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n - 1):
		(m1, m2) = (max(a[i], a[i + 1]), min(a[i], a[i + 1]))
		while 2 * m2 < m1:
			c += 1
			m2 *= 2
	k.append(c)
for i in k:
	print(i)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		if max(a[i], a[i + 1]) > 2 * min(a[i], a[i + 1]):
			temp = math.log(max(a[i + 1], a[i]) / min(a[i + 1], a[i]), 2)
			t = int(temp)
			if t == temp:
				ans += t - 1
			else:
				ans += t
	print(int(ans))


try:
	t = int(input())
	for i in range(0, t):
		n = int(input())
		a = list(map(int, input().split(' ')))
		c = 0
		for i in range(0, len(a) - 1):
			if max(a[i], a[i + 1]) > 2 * min(a[i], a[i + 1]):
				p = max(a[i], a[i + 1])
				q = min(a[i], a[i + 1])
				while q * 2 < p:
					q *= 2
					c += 1
		print(c)
except:
	pass


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
tc = 1
(tc,) = inp()
for _ in range(tc):
	(n,) = inp()
	a = inp()
	ans = 0
	for i in range(n - 1):
		(b, c) = (a[i], a[i + 1])
		if b > c:
			(b, c) = (c, b)
		while 2 * b < c:
			ans += 1
			b = 2 * b
	print(ans)


a = int(input())
for i in range(a):
	answer = 0
	b = int(input())
	s = list(map(int, input().split()))
	for j in range(b - 1):
		max_ = max(s[j], s[j + 1])
		min_ = min(s[j], s[j + 1])
		while max_ / min_ > 2:
			answer += 1
			min_ *= 2
	print(answer)


def solve():
	n = int(input())
	A = list(map(int, input().split(' ')))
	ans = 0
	for i in range(n - 1):
		(u, v) = (A[i], A[i + 1])
		if u > v:
			(u, v) = (v, u)
		while 2 * u < v:
			u *= 2
			ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


def solve(arr):
	s = 0
	for i in range(len(arr) - 1):
		(a, b) = (arr[i], arr[i + 1])
		if a > b:
			(a, b) = (b, a)
		if a == b:
			s += 1
		while a < b:
			a *= 2
			s += 1
		s -= 1
	return s
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans.append(solve(arr))
for i in ans:
	print(i)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(count, i) = (0, 0)
	while i < n - 1:
		next = arr[i + 1]
		cur = arr[i]
		maxi = max(next, cur)
		mini = min(next, cur)
		while 2 * mini < maxi:
			mini *= 2
			count += 1
		i += 1
	print(count)


import sys
import math
nCases = sys.stdin.readline().rstrip('\n')

def steps(big, small):
	if big <= 2 * small:
		return 0
	return math.ceil(math.log2(big / small)) - 1
for i in range(int(nCases)):
	n = sys.stdin.readline().rstrip('\n')
	arr = sys.stdin.readline().rstrip('\n').split(' ')
	cnt = 0
	for i in range(1, len(arr)):
		cnt += steps(max(int(arr[i - 1]), int(arr[i])), min(int(arr[i - 1]), int(arr[i])))
	print(cnt)


def densing(g, h):
	i = 0
	while g / h > 2:
		g /= 2
		i += 1
	globals()['r'] += i

def raf():
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	global r
	r = 0
	while i < n - 1:
		g = max(l[i], l[i + 1])
		h = min(l[i], l[i + 1])
		if g / h > 2:
			densing(g, h)
		i += 1
	print(r)

def main():
	t = int(input())
	while t:
		raf()
		t -= 1
main()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	p = None
	r = 0
	for i in map(int, input().split()):
		if p is not None:
			if i >= p:
				while p * 2 < i:
					p *= 2
					r += 1
			else:
				x = i
				while x * 2 < p:
					x *= 2
					r += 1
		p = i
	print(r)
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n - 1):
		if max(a[i], a[i + 1]) <= 2 * min(a[i], a[i + 1]):
			pass
		else:
			x = min(a[i], a[i + 1])
			y = max(a[i], a[i + 1])
			while True:
				x = 2 * x
				c += 1
				if y <= 2 * x:
					break
	print(c)


t = int(input())
for i in range(t):
	n = input()
	a = list(map(int, input().split()))
	count = 0
	for g in range(int(n) - 1):
		k = max(a[g], a[g + 1]) / min(a[g], a[g + 1])
		if k > 2:
			ma = max(a[g], a[g + 1])
			mi = min(a[g], a[g + 1])
			d = 0
			while ma > mi:
				d += 1
				mi *= 2
			d -= 1
			count += d
		else:
			continue
	print(count)


from sys import stderr

def dbp(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def get_int_list():
	return [int(x) for x in input().strip().split()]

def do_thing():
	n = int(input().strip())
	alist = get_int_list()
	adds = 0
	for (idx, a) in enumerate(alist):
		if idx == 0:
			continue
		(les, gre) = (alist[idx - 1], alist[idx])
		if gre < les:
			(les, gre) = (gre, les)
		while les * 2 < gre:
			les *= 2
			adds += 1
	return adds

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


num = int(input())
for i in range(num):
	size = int(input())
	arr = list(map(int, input().rstrip().split()))
	ans = 0
	tmp = 0
	for i in range(size - 1):
		if arr[i] > arr[i + 1] * 2:
			tmp = arr[i + 1]
			while arr[i] > tmp * 2:
				tmp = tmp * 2
				ans = ans + 1
		elif arr[i] * 2 < arr[i + 1]:
			tmp = arr[i]
			while arr[i + 1] > tmp * 2:
				tmp = tmp * 2
				ans = ans + 1
	print(ans)


def L(a):
	for q in range(len(a) - 1):
		if max(a[q], a[q + 1]) / min(a[q], a[q + 1]) > 2:
			return False
	return True
t = int(input())
for j in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	f = True
	k = 0
	while not L(a):
		for i in range(n - 1):
			if max(a[i], a[i + 1]) / min(a[i], a[i + 1]) > 2:
				if a[i] == max(a[i], a[i + 1]):
					a.insert(i + 1, a[i + 1] * 2)
				else:
					a.insert(i + 1, a[i] * 2)
				k += 1
				n += 1
	print(k)


def ret(l):
	r = 0
	i = 0
	while i < len(l) - 1:
		if l[i + 1] > 2 * l[i]:
			r += 1
			l.insert(i + 1, 2 * l[i])
		elif 2 * l[i + 1] < l[i]:
			r += 1
			l.insert(i + 1, 2 * l[i + 1])
			i -= 1
		i += 1
	return r
t = int(input())
for k in range(t):
	n = int(input())
	lst = [int(x) for x in input().split()]
	print(ret(lst))


def arrIn():
	return list(map(int, input().split()))

def mapIn():
	return map(int, input().split())

def process(a, b):
	count = 0
	c = (a + 1) // 2
	while c > b:
		b = b * 2
		count += 1
	return count
for i in range(int(input())):
	n = int(input())
	arr = arrIn()
	sum = 0
	for i in range(1, n):
		sum += process(max(arr[i], arr[i - 1]), min(arr[i], arr[i - 1]))
	print(sum)


def cf_702A(numbers: list):
	answer = 0
	for i in range(len(numbers) - 1):
		(b, a) = sorted([numbers[i], numbers[i + 1]])
		if not a > 2 * b:
			continue
		while 2 * b < a:
			b *= 2
			answer += 1
	return answer
for _ in range(int(input())):
	n = int(input())
	print(cf_702A(list(map(int, input().split()))))


def dense_arr(e1, e2):
	arr = []
	ele1 = min(e1, e2)
	ele2 = max(e1, e2)
	while True:
		if not ele2 / ele1 <= 2:
			arr.append((ele2 + 1) // 2)
			ele2 = (ele2 + 1) // 2
		else:
			break
	return arr
cnt = int(input())
for c in range(cnt):
	n = int(input())
	array = list(map(int, input().split()))
	sum = 0
	for i in range(n - 1):
		arr = dense_arr(array[i], array[i + 1])
		sum += len(arr)
	print(sum)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	ans = 0
	for i in range(len(arr) - 1):
		min = arr[i] if arr[i] < arr[i + 1] else arr[i + 1]
		max = arr[i + 1] if arr[i] < arr[i + 1] else arr[i]
		if max / min > 2:
			while max > 2 * min:
				ans += 1
				if max % 2 == 0:
					max //= 2
				else:
					max = max // 2 + 1
	print(ans)


for _ in range(int(input())):
	x = int(input())
	arr = list(map(int, input().split()))
	if x == 1:
		print(0)
		break
	y = 0
	for i in range(x - 1):
		q = max(arr[i], arr[i + 1]) / min(arr[i], arr[i + 1])
		if q > 2.0:
			j = 2
			while j < q:
				j *= 2
				y += 1
	print(y)


import sys
import math
from collections import defaultdict, Counter, deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for j in range(1, n):
		ma = max(a[j], a[j - 1])
		mi = min(a[j], a[j - 1])
		while ma > 2 * mi:
			mi *= 2
			ans += 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	__ = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(len(a) - 1):
		diff = math.ceil(abs(a[i] - a[i + 1]) / min(a[i], a[i + 1]))
		if max(a[i], a[i + 1]) > min(a[i], a[i + 1]) * 2:
			s += math.floor(math.log(diff, 2))
	print(s)


def func(x, y):
	if x > y:
		a = y
		y = x
		x = a
	cnt = 0
	while 2 * x < y:
		x *= 2
		cnt += 1
	return cnt
t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	lst = x.split()
	ans = 0
	for j in range(n - 1):
		y = func(int(lst[j]), int(lst[j + 1]))
		ans += y
	print(ans)


from math import log2, floor

def largestPow2(p, q):
	count = -1
	perfect = False
	while q < p:
		q = 2 * q
		count += 1
	if p == q:
		perfect = True
		return (count + 1, perfect)
	else:
		return (count, perfect)

def makeDense(arr, n):
	count = 0
	for idx in range(n - 1):
		a = arr[idx]
		b = arr[idx + 1]
		temp = largestPow2(max(a, b), min(a, b))
		if temp[1] == True and temp[0] != 0:
			count += temp[0] - 1
		else:
			count += temp[0]
	return count

def denseArray():
	ncases = int(input())
	for n in range(ncases):
		num = int(input())
		arr = list(map(int, input().split()))
		print(makeDense(arr, num))
denseArray()


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	r = 0
	for (x, y) in map(sorted, zip(a, a[1:])):
		while x * 2 < y:
			x *= 2
			r += 1
	print(r)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	daf = list(map(int, input().split()))
	has = 0
	for i in range(1, n):
		max_value = max(daf[i], daf[i - 1])
		min_value = min(daf[i], daf[i - 1])
		com = max_value / min_value
		if com > 2:
			has += math.ceil(math.log(com, 2)) - 1
	print(has)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n - 1):
		m = min(a[i], a[i + 1])
		n = max(a[i], a[i + 1])
		while 2 * m < n:
			c += 1
			m *= 2
	print(c)


def denseArr(n, arr):
	count = 0
	for i in range(0, n - 1):
		minimum = min(arr[i], arr[i + 1])
		maximum = max(arr[i], arr[i + 1])
		while maximum > 2 * minimum:
			count += 1
			minimum *= 2
	print(count)
	return
tc = int(input())
for _ in range(0, tc):
	n = int(input())
	arr = [int(i) for i in input().split()][:n]
	denseArr(n, arr)


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		a = max(arr[i], arr[i + 1])
		b = min(arr[i], arr[i + 1])
		while 2 * b < a:
			b *= 2
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	the_num_of_additional_numbers = 0
	for ind in range(1, n):
		local_max = max(a[ind - 1], a[ind])
		local_min = min(a[ind - 1], a[ind])
		if local_max / local_min > 2:
			relation = local_max / local_min
			while relation > 2:
				relation /= 2
				the_num_of_additional_numbers += 1
	print(the_num_of_additional_numbers)


t = int(input())
for i in range(0, t):
	n = int(input())
	c = 0
	a = [int(x) for x in input().split()]
	for j in range(0, n):
		if j < n - 1:
			y = min(a[j], a[j + 1])
			x = max(a[j], a[j + 1]) // y
			for k in range(0, x):
				if max(a[j], a[j + 1]) > 2 * y:
					c = c + 1
					y = y * 2
	print(c)


from math import log, ceil
for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		(a, b) = sorted([s[i], s[i - 1]])
		ans += max(ceil(log(b / a, 2)) - 1, 0)
	print(ans)


def solution():
	n = int(input())
	a = [int(i) for i in input().split()]
	prev = a[0]
	k = 0
	for i in range(1, n):
		if max(a[i], prev) / min(a[i], prev) <= 2:
			prev = a[i]
			continue
		else:
			prev_c = a[i]
			if prev < a[i]:
				while prev * 2 < a[i]:
					prev *= 2
					k += 1
			else:
				prev_c = a[i]
				while a[i] * 2 < prev:
					a[i] *= 2
					k += 1
			prev = prev_c
	print(k)
for t in range(int(input())):
	solution()


import math
t = int(input())
for i in range(t):
	n = int(input())
	w = []
	k = input().split()
	w.extend(k)
	for j in range(n):
		w[j] = int(w[j])
	ans = 0
	for j in range(n - 1):
		if w[j] == w[j + 1]:
			continue
		ans += math.ceil(math.log2(max(w[j], w[j + 1]) / min(w[j], w[j + 1]))) - 1
	print(ans)


a = int(input())
for i in range(a):
	c = int(input())
	b = [int(i) for i in input().split()]
	g = 0
	for j in range(1, len(b)):
		k = max(b[j], b[j - 1]) / min(b[j], b[j - 1])
		while k > 2:
			k = k / 2
			g += 1
	print(g)


from sys import stdin
input = iter(stdin.read().split())
scanInt = lambda : int(next(input))

def mu2(a, b):
	if a > b:
		(a, b) = (b, a)
	(c, a) = (0, a << 1)
	while a < b:
		(c, a) = (c + 1, a << 1)
	return c
for t in range(scanInt()):
	(n, s) = (scanInt(), 0)
	prv = scanInt()
	for _ in range(n - 1):
		cur = scanInt()
		s += mu2(prv, cur)
		prv = cur
	print(s)