Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $n$ days from Petya's live and you have to determine what happened with his flower in the end.

The flower grows as follows:

If the flower isn't watered for two days in a row, it dies.

If the flower is watered in the $i$-th day, it grows by $1$ centimeter.

If the flower is watered in the $i$-th and in the $(i-1)$-th day ($i > 1$), then it grows by $5$ centimeters instead of $1$.

If the flower is not watered in the $i$-th day, it does not grow.

At the beginning of the $1$-st day the flower is $1$ centimeter tall. What is its height after $n$ days?


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.

The first line of each test case contains the only integer $n$ ($1 \leq n \leq 100$).

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($a_i = 0$ or $a_i = 1$). If $a_i = 1$, the flower is watered in the $i$-th day, otherwise it is not watered.


-----Output-----

For each test case print a single integer $k$ — the flower's height after $n$ days, or $-1$, if the flower dies.


-----Examples-----

Input
4
3
1 0 1
3
0 1 1
4
1 0 0 1
1
0
Output
3
7
-1
1


-----Note-----

None

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
def solution(lst):
	watered_yesterday = None
	height = 1
	for watered in lst:
		if watered:
			if watered_yesterday:
				height += 5
				_hy_anon_var_1 = None
			else:
				height += 1
				_hy_anon_var_1 = None
			_hy_anon_var_3 = _hy_anon_var_1
		else:
			if not watered_yesterday is None and (not watered_yesterday):
				return -1
				_hy_anon_var_2 = None
			else:
				_hy_anon_var_2 = None
			_hy_anon_var_3 = _hy_anon_var_2
		watered_yesterday = watered
	return height
import sys

def _hy_anon_var_4(*_hyx_GXUffffX26):
	t = int(input())
	for _ in range(t):
		n = int(input())
		lst = list(map(int, input().split()))
		print(solution(lst))
_hyx_GXUffffX25 = _hy_anon_var_4(*sys.argv)
_hy_anon_var_5 = sys.exit(_hyx_GXUffffX25) if isinstance(_hyx_GXUffffX25, int) else None


for _ in range(int(input())):
	input()
	li = list(map(int, input().split()))
	days_not_watered = int(not li[0])
	x = li[0] + 1
	for i in range(1, len(li)):
		if days_not_watered == 2:
			x = -1
			break
		if li[i - 1] == 1 and li[i] == 1:
			x += 5
			days_not_watered = 0
		elif li[i] == 1:
			x += 1
			days_not_watered = 0
		else:
			days_not_watered += 1
			if days_not_watered == 2:
				x = -1
				break
	print(x)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 1
	for i in range(n):
		if l[i] == 0:
			if i > 0:
				if l[i - 1] == 0:
					ans = -1
					break
		elif i > 0:
			if l[i - 1] == 0:
				ans += 1
			else:
				ans += 5
		else:
			ans += 1
	print(ans)


t = int(input())
for u in range(t):
	n = int(input())
	ans = 1
	l = list(map(int, input().split()))
	f = 1
	for i in range(n):
		if i == 0:
			if l[i]:
				ans += 1
		else:
			if l[i] == 0 and l[i - 1] == 0:
				print(-1)
				f = 0
				break
			if l[i] == 1:
				if l[i - 1] == 1:
					ans += 5
				else:
					ans += 1
	if f:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = 1
	ok = True
	for i in range(n):
		if i == 0:
			if arr[i] == 1:
				ans += 1
		else:
			if arr[i] == 0 and arr[i - 1] == 0:
				ok = False
			if arr[i] == 1 and arr[i - 1] == 1:
				ans += 5
			elif arr[i] == 1:
				ans += 1
	if not ok:
		ans = -1
	print(ans)


from sys import stdin, stdout
import math
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = 1
	if a[0] == 1:
		ans += 1
	check = False
	for i in range(1, n):
		if a[i] == 1 and a[i - 1] == 1:
			ans += 5
		elif a[i] == 1 and a[i - 1] != 1:
			ans += 1
		elif a[i] != 1 and a[i - 1] != 1:
			check = True
			break
	if check:
		print('-1')
	else:
		print(ans)


for s in [*open(0)][2::2]:
	h = 1
	p = True
	for (i, x) in enumerate([*map(int, s.split())]):
		if x:
			if i and p:
				h += 5
			else:
				h += 1
		elif not p:
			print(-1)
			break
		p = x
	else:
		print(h)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(a) for a in input().split()]
	rost = 1
	k = 0
	for i in range(n):
		if i > 0 and a[i] == 1 and (a[i - 1] == 1):
			rost += 5
		elif a[i] == 1:
			rost += 1
			k = 0
		else:
			k += 1
		if k >= 2:
			print(-1)
			break
	else:
		print(rost)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1 + a[0]
	for i in range(1, n):
		if a[i] and a[i - 1]:
			ans += 5
		elif a[i]:
			ans += 1
		elif not a[i - 1]:
			ans = -1
			break
	print(ans)
	t -= 1


t = int(input())
for q in range(t):
	n = int(input())
	tek = 1
	a = list(map(int, input().split()))
	for i in range(n):
		if i > 0 and a[i] == 0 and (a[i - 1] == 0):
			tek = -1
			break
		if i > 0 and a[i] == 1 and (a[i - 1] == 1):
			tek += 5
		elif a[i] == 1:
			tek += 1
	print(tek)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	height = 1
	for i in range(len(a)):
		if i == 0:
			if a[i] == 1:
				height += 1
		elif a[i] == 1 and a[i - 1] == 1:
			height += 5
		elif a[i] == 1:
			height += 1
		elif a[i] == 0 and a[i - 1] == 0:
			height = -1
		if height == -1:
			break
	print(height)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	a = 1
	if li[0] == 1:
		a = a + 1
	for i in range(1, n):
		if li[i] == 1:
			if li[i - 1] == 1:
				a = a + 5
			else:
				a = a + 1
		elif li[i - 1] == 0:
			a = -1
			break
	print(a)


def solve():
	N = int(input())
	D = [int(x) for x in input().split()]
	L = 1
	for d in range(N):
		if d > 0 and D[d - 1] == 1 and (D[d] == 1):
			L += 5
		elif D[d] == 1:
			L += 1
		elif d > 0 and D[d - 1] == 0:
			return -1
	return L
T = int(input())
for i in range(T):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	k = 1
	if arr[0] == 1:
		k += 1
	for i in range(1, n):
		if arr[i] == 1:
			if arr[i - 1] == 1:
				k += 5
			else:
				k += 1
		elif arr[i - 1] == 0:
			k = -1
			break
	print(k)


t = int(input())
while t:
	n = int(input())
	a = map(int, input().split())
	prev = -1
	res = 1
	for i in a:
		if prev == 1 and i == 1:
			res += 5
		if prev != 1 and i == 1:
			res += 1
		if prev == 0 and i == 0:
			res = -1
			break
		prev = i
	print(res)
	t -= 1


m = int(input())
for q in range(m):
	days = int(input())
	size = 1
	schedule = list(map(int, input().split()))
	if schedule[0] == 1:
		size += 1
	f = True
	for i in range(1, days):
		if schedule[i] == 1:
			if schedule[i - 1] == 1:
				size += 5
			else:
				size += 1
		elif schedule[i - 1] == 0:
			f = False
	if not f:
		print(-1)
	else:
		print(size)


t = int(input())
for i in range(t):
	n = int(input())
	mas = [int(i) for i in input().split()]
	k = 1
	for j in range(len(mas)):
		if j == 0:
			if mas[j] == 1:
				k += 1
		elif mas[j - 1] == 1 and mas[j] == 1:
			k += 5
		elif mas[j - 1] == 0 and mas[j] == 1:
			k += 1
		elif mas[j - 1] == 0 and mas[j] == 0:
			k = -1
			break
	print(k)


t = int(input())
res = [1] * t
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if res[j] != -1:
			if a[i]:
				if i > 0:
					if a[i - 1]:
						res[j] += 4
				res[j] += 1
			elif i > 0:
				if not a[i - 1]:
					res[j] = -1
print(*res, sep='\n')


import sys

def f(l, n, f):
	a = 0
	x = n - 1
	while a <= x:
		m = a + (x - a) // 2
		if l[m] == f:
			return m
		elif l[m] > f:
			x = m - 1
		else:
			a = m + 1
	return None
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	l = list(map(int, sys.stdin.readline().split()))
	h = 1
	for i in range(n):
		if i > 0:
			if l[i - 1] == 1 and l[i] == 1:
				h = h + 5
			elif l[i - 1] == 0 and l[i] == 1:
				h = h + 1
			elif l[i - 1] == 0 and l[i] == 0:
				print(-1)
				break
			else:
				continue
		elif l[i] == 1:
			h = h + 1
		else:
			continue
	else:
		print(h)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 1
	for x in range(n):
		if x == 0:
			if A[x] == 1:
				ans += 1
		elif A[x] == 1 and A[x - 1] == 1:
			ans += 5
		elif A[x] == 1:
			ans += 1
		elif A[x] == 0 and A[x - 1] == 0:
			ans = -1
			break
	print(ans)


import math

def test():
	n = int(input())
	a = list(map(int, input().split()))
	rost = 1
	if a[0] == 1:
		rost = 2
	for i in range(1, n):
		if a[i] == 1 and a[i - 1] == 1:
			rost += 5
		elif a[i] == 1:
			rost += 1
		elif a[i] == 0 and a[i - 1] == 0:
			rost = -1
			break
	print(rost)
t = int(input())
for i in range(t):
	test()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	height = 1 if arr[0] == 0 else 2
	flag = True
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			if arr[i] == 0:
				flag = False
				break
			else:
				height += 5
		elif arr[i] == 1:
			height += 1
	print(height if flag else -1)


k = int(input())
for _ in range(k):
	n = int(input())
	A = list(map(int, input().split()))
	R = 1
	flag = 1
	for i in range(n - 1):
		if A[i + 1] and A[i]:
			R += 5
		elif A[i]:
			R += 1
		elif A[i + 1] == 0 and A[i] == 0:
			print(-1)
			flag = 0
			break
	if flag:
		if A[-1] == 1:
			print(R + 1)
		else:
			print(R)


for i in range(int(input())):
	c = 1
	n = input()
	a = [int(x) for x in input().split()]
	for i in range(len(a)):
		try:
			if a[i] == 1 and a[i + 1] == 1:
				c += 5
			elif a[i] == 1:
				c += 1
			elif a[i] == 0 and i != 0 and (a[i - 1] == 0):
				c = -1
				print(c)
				break
		except:
			c += 1
	if c != -1:
		print(c)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	alive = True
	len = 1
	if arr[0] == 1:
		len += 1
	for j in range(1, n):
		if arr[j] == 0:
			if arr[j - 1] == 0:
				alive = False
		if arr[j] == 1:
			len += 1
			if arr[j - 1] == 1:
				len += 4
	if alive == False:
		len = -1
	print(len)


for _ in range(int(input())):
	n = int(input())
	l0 = list(map(int, input().split()))
	su = 1
	for i in range(n):
		if i != 0:
			if l0[i] == l0[i - 1] and l0[i] == 0:
				su = -1
				break
			elif l0[i] == l0[i - 1] and l0[i] == 1:
				su += 5
			elif l0[i] == 1:
				su += 1
			else:
				su = su
		elif l0[i] == 1:
			su += 1
	print(su)


t = int(input())
for i in range(t):
	n = int(input())
	bush = [int(a) for a in input().split()]
	s = 1
	if bush[0] == 1:
		s += 1
	for j in range(1, n):
		if bush[j] == 1 and bush[j - 1] == 1:
			s += 5
			continue
		elif bush[j] == 1 and bush[j - 1] == 0:
			s += 1
			continue
		elif bush[j] == 0 and bush[j - 1] == 1:
			continue
		elif bush[j] == 0 and bush[j - 1] == 0:
			print(-1)
			break
	else:
		print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 1
	die = 0
	if n == 1:
		if a[0] == 1:
			print(2)
		else:
			print(1)
	else:
		for i in range(len(a)):
			if a[i] == 0 and i > 0:
				if a[i - 1] == 0:
					count = -1
					break
				else:
					die = 1
			elif a[i] == 1:
				if i == 0:
					count += 1
				elif i != 0:
					if a[i - 1] == 1:
						count += 5
					else:
						count += 1
		print(count)


t = int(input())
h = 1
for _ in range(t):
	n = int(input())
	days = list(map(int, input().split()))
	days.insert(0, 'w')
	for i in range(1, n + 1):
		if days[i] == 1:
			if days[i - 1] == 1:
				h += 5
			else:
				h += 1
		elif days[i] == 0:
			if days[i - 1] == 0:
				h = -1
				break
	print(h)
	h = 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	h = 1
	f = 0
	if a[0] == 1:
		h = h + 1
	for i in range(1, n):
		if a[i] == 0 and a[i - 1] == 0:
			h = -1
			break
		elif a[i] == 1 and a[i - 1] == 1:
			h = h + 5
		elif a[i] == 1:
			h = h + 1
	print(h)


t = int(input())
rost = []
for i in range(t):
	n = int(input())
	days = input()
	if '00' in days.replace(' ', ''):
		rost.append(-1)
		continue
	povtor = 0
	rost.append(1)
	days = list(map(int, days.split()))
	for day in days:
		if day == 1:
			if povtor == 1:
				rost[i] += 5
			else:
				rost[i] += 1
				povtor = 1
		else:
			povtor = 0
for i in rost:
	print(i)


n = int(input())
for i in range(n):
	t = int(input())
	c = list(map(int, input().split()))
	value = 1
	if c[0] == 1:
		value = 2
	for i in range(1, t):
		if c[i] == 0 and c[i - 1] == 0:
			value = -1
			break
		elif c[i] == 1 and c[i - 1] == 1:
			value += 5
		elif c[i] == 1:
			value += 1
	print(value)


t = int(input())
for i in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	d = 0
	k = 1
	r = 0
	for i in range(n):
		if m[i] == 1:
			if d > 0:
				k += 5
			else:
				k += 1
				d = 1
		else:
			if d == 0 and i > 0:
				r = 1
			d = 0
	if r == 1:
		print(-1)
	else:
		print(k)


t = int(input())
for i in range(t):
	n = int(input())
	s = 1
	l = '0'
	first = True
	for a in input().split():
		if first:
			if a == '1':
				s += 1
				l = '1'
			first = False
		elif a == '1':
			if l == '1':
				s += 5
			else:
				s += 1
				l = '1'
		elif l == '1':
			l = '0'
		else:
			print(-1)
			first = None
			break
	if first is not None:
		print(s)


t = int(input())
ans = []
for i in range(t):
	l = 1
	n = int(input())
	sp = list(map(int, input().split(' ')))
	a = sp[0]
	if a == 1:
		l += 1
	for i in range(1, len(sp)):
		if sp[i] == 0 and a == 0:
			l = -1
			break
		if sp[i] == 1 and a == 1:
			l += 5
		elif sp[i] == 1 and a == 0:
			l += 1
		a = sp[i]
	ans.append(l)
for i in ans:
	print(i)


t = int(input())

def Plant(log):
	watered = True
	day1 = True
	height = 1
	for i in log:
		if day1:
			if i == '1':
				watered = True
				height += 1
				day1 = False
			else:
				watered = False
				day1 = False
		elif watered == False and i == '1':
			watered = True
			height += 1
		elif watered == False and i == '0':
			return '-1'
		elif watered == True and i == '0':
			watered = False
		elif watered == True and i == '1':
			height += 5
	return height
for w in range(t):
	n = int(input())
	x = input().split(' ')
	diagnosis = Plant(x)
	print(diagnosis)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	h = 1
	p = 2
	for i in a:
		if i == 1:
			if p == 1:
				h += 4
			h += 1
			p = 1
		elif p == 0:
			h = -1
			break
		else:
			p = 0
	print(h)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 1
	fd = 0
	if a[0] == 0:
		fd = 1
	else:
		k += 1
	for i in range(1, n):
		if a[i] == 0 and fd == 1:
			print(-1)
			break
		elif a[i] == 0 and fd == 0:
			fd = 1
		elif a[i] == 1 and a[i - 1] == 0:
			k += 1
			fd = 0
		else:
			k += 5
			fd = 0
	else:
		print(k)


def ans(arr, n):
	l = 1
	for i in range(n):
		if arr[i] == 0 and arr[i + 1] == 0:
			return -1
		elif arr[i] == 1 and arr[i - 1] == 1:
			l += 5
		elif arr[i] == 1:
			l += 1
	return l
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.append(1000)
	print(ans(arr, n))


answer = []
for i in range(int(input())):
	last_day = 2
	flower = 1
	n = int(input())
	for day in [int(_) for _ in input().split()]:
		if day == 0 and last_day == 0:
			flower = -1
			break
		elif day == 1 and last_day != 1:
			flower += 1
		elif day == 1 and last_day == 1:
			flower += 5
		last_day = day
	answer.append(flower)
for i in answer:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	h = 1
	count_0 = 0
	if a[0] == 0:
		count_0 = 1
	else:
		h += 1
	for i in range(1, n):
		if a[i] == 1 and a[i - 1] == 1:
			h += 5
			count_0 = 0
		elif a[i] == 1:
			h += 1
			count_0 = 0
		elif a[i] == 0:
			count_0 += 1
		if count_0 == 2:
			print(-1)
			break
	else:
		print(h)


t = int(input())
all = []
for _ in range(t):
	counter = 1
	n = int(input())
	a = list(map(int, input().split()))
	if len(a) == 1:
		if a[0] == 1:
			all.append(2)
		else:
			all.append(1)
	else:
		if a[0] == 1:
			counter += 1
		for i in range(1, n):
			if a[i - 1] == 0 and a[i] == 0:
				counter = -1
				break
			elif a[i - 1] == 0 and a[i] == 1:
				counter += 1
			elif a[i - 1] == 1 and a[i] == 1:
				counter += 5
		all.append(counter)
for el in all:
	print(el)


for _ in range(int(input())):
	k = 1
	isalive = True
	_ = input()
	a = input().split()
	for i in range(len(a)):
		if not isalive:
			break
		if a[i] == '1':
			k += 5 if i != 0 and a[i - 1] == '1' else 1
		elif i != 0 and a[i - 1] == '0':
			isalive = False
	print(k if isalive else -1)


amm = int(input())
ans = []
for i in range(amm):
	len_ = int(input())
	days = [int(x) for x in input().split(' ')]
	pred = -1
	a = 1
	dead = False
	for i in days:
		if pred == 0 and i == 0:
			ans.append(-1)
			dead = True
			break
		elif pred == 1 and i == 1:
			a += 5
		elif pred != 1 and i == 1:
			a += 1
		pred = i
	if not dead:
		ans.append(a)
for i in ans:
	print(i)


def getplantStat(waterStat, n):
	height = 1
	for index in range(n):
		if index == 0:
			if waterStat[index] == 1:
				height += 1
			continue
		if waterStat[index] == 0:
			if waterStat[index - 1] == 0:
				return -1
		elif waterStat[index] == 1:
			if waterStat[index - 1] == 0:
				height += 1
			elif waterStat[index - 1] == 1:
				height += 5
	return height
T = int(input())
opList = list()
for t in range(T):
	n = int(input())
	waterStat = [int(i) for i in input().split()]
	op = getplantStat(waterStat, n)
	opList.append(op)
for op in opList:
	print(op)


kl = int(input())
for kkl in range(kl):
	n = int(input())
	a = list(map(int, input().split()))
	rz = 1
	pr = 3
	for i in range(n):
		if pr == 2:
			continue
		if a[i] == 0 and pr == 0:
			pr = 2
		elif a[i] == 0 and (pr == 1 or pr == 3):
			pr = 0
		elif a[i] == 1 and pr == 1:
			rz += 5
		elif a[i] == 1 and (pr == 0 or pr == 3):
			rz += 1
			pr = 1
	if pr == 2:
		print(-1)
	else:
		print(rz)


t = int(input())
ans = []
for i in range(t):
	l = 1
	n = int(input())
	s = input()
	if '0 0' in s:
		l = -1
		ans.append(l)
		continue
	a = [int(j) for j in s.split()]
	if a[0] == 1:
		l += 1
	for j in range(1, len(a)):
		if a[j] == 1:
			if a[j - 1] == 1:
				l += 5
			else:
				l += 1
	ans.append(l)
for i in ans:
	print(i)


def main():
	for i in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		flowers = 1
		for k in range(len(a)):
			if a[k] == 1:
				flowers += 1
			if a[k] == 1 and a[k - 1] == 1 and (k != 0):
				flowers += 4
			if a[k] == 0 and a[k - 1] == 0 and (k != 0):
				flowers = -1
				break
		print(flowers)
main()


def grow_counter(days):
	if days[0] == 1:
		grow = 2
	else:
		grow = 1
	for i in range(1, len(days)):
		if days[i - 1] == 0 and days[i] == 0:
			return -1
		if days[i - 1] == 1 and days[i] == 1:
			grow += 5
			continue
		if days[i] == 1:
			grow += 1
	return grow
for _ in range(int(input())):
	_ = input()
	print(grow_counter(list(map(int, input().split()))))


t = int(input())
for i in range(t):
	d = int(input())
	l = list(map(int, input().split()))
	ans = 1
	for j in range(d):
		if j != 0:
			if l[j] == 0 and l[j - 1] == 0:
				ans = -1
				break
			elif l[j] == 1 and l[j - 1] == 1:
				ans = ans + 5
			elif l[j] == 1 and l[j - 1] != 1:
				ans = ans + 1
		elif l[j] == 1:
			ans = ans + 1
	print(ans)


n = int(input())
for j in range(n):
	d = int(input())
	pol = list(map(int, input().split()))
	counter = 1
	i = 0
	while i < d - 1:
		if pol[i] == 0 and pol[i + 1] == 0:
			counter = -1
			break
		elif pol[i] == 1 and pol[i + 1] == 1:
			counter += 5
			i += 1
		elif pol[i] == 1:
			counter += 1
			i += 1
		elif pol[i] == 0:
			i += 1
	if pol[-1] == 1 and counter != -1:
		counter += 1
	print(counter)


t = int(input())

def flower(n, array):
	res = 1
	if array[0]:
		res += 1
	for i in range(1, n):
		if not array[i - 1] and (not array[i]):
			return -1
		elif array[i - 1] and array[i]:
			res += 5
		elif array[i]:
			res += 1
	return res
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	print(flower(n, array))


t = int(input())
listing = []
for i in range(t):
	a = input()
	b = input()
	c = b.split(' ')
	newList = ''
	for j in c:
		newList += str(j)
	listing.append(newList)
for i in listing:
	string = i
	length = 1
	if '00' in string:
		print(-1)
		continue
	else:
		if string[0] != '0':
			length += 1
		for j in range(1, len(string), 1):
			if string[j] == '1':
				if string[j - 1] == '1':
					length += 5
				else:
					length += 1
	print(length)


t = int(input())
for i in range(t):
	k = 1
	a = int(input())
	c = list(map(int, input().split()))
	if len(c) == 1:
		if c[0] == 1:
			k = k + 1
		if c[0] == 0:
			k = 1
	else:
		k = 1
		for j in range(len(c) - 1):
			if c[j + 1] == 1:
				k = k + 1
			if c[j + 1] + c[j] == 2:
				k = k + 5 - 1
			if c[j + 1] + c[j] == 0:
				k = k - 1 - k
				break
		if c[0] == 1 and k != -1:
			k = k + 1
	print(k)


for _ in range(int(input())):
	lenght = 1
	i = 0
	trash = int(input())
	day = [int(v) for v in input().split()]
	if day[0] == 0:
		i += 1
	else:
		lenght += 1
	for c in range(1, len(day)):
		if day[c] == 1:
			i = 0
			if day[c - 1] == 1:
				lenght += 5
			else:
				lenght += 1
		else:
			i += 1
			if i == 2:
				lenght = -1
				break
	print(lenght)
	lenght = 1
	i = 0


def main():
	m = int(input())
	for j in range(m):
		n = int(input())
		l = list(map(int, input().split()))
		leng = 1
		f = True
		if l[0] == 1:
			leng += 1
		for i in range(1, n):
			if l[i] == 1:
				if l[i - 1] == 1:
					leng += 5
				else:
					leng += 1
			elif l[i - 1] == 0:
				print(-1)
				f = False
				break
		if f:
			print(leng)
main()


p = int(input())
answ = []
for l in range(p):
	n = int(input())
	a = ''.join(input().split())
	t = 0
	k = 1
	if '00' in a:
		answ.append(-1)
		continue
	a = a.split('0')
	for i in a:
		if i:
			if len(i) > 1:
				k += 5 * (len(i) - 1) + 1
			elif len(i) == 1:
				k += 1
	answ.append(k)
print(*answ, sep='\n')


def growth(n, L):
	h = 1
	if L[0] == '0':
		pass
	if L[0] == '1':
		h += 1
	for i in range(1, n):
		if L[i] == '0':
			if L[i - 1] == '0':
				return -1
		elif L[i - 1] == '0':
			h += 1
		else:
			h += 5
	return h
cases = int(input())
for i in range(cases):
	n = int(input())
	L = input().split()
	print(growth(n, L))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	h = 1
	last = arr[0]
	if last:
		h += 1
	pas = False
	for x in arr[1:]:
		if pas:
			continue
		if x == 0 and last == 0:
			print(-1)
			pas = True
		if x and last:
			h += 5
		elif x:
			h += 1
		last = x
	if not pas:
		print(h)


t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	height = 1
	dead = 0
	for i in range(n):
		if arr[i] == 1:
			if i > 0 and arr[i - 1] == 1:
				height += 5
			else:
				height += 1
		if i > 0 and arr[i] == 0 and (arr[i - 1] == 0):
			dead = 1
	if dead:
		print(-1)
	else:
		print(height)


kolvo = int(input())
answers = []
for i in range(kolvo):
	ans = 1
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if i >= 1:
			present = a[i]
			past = a[i - 1]
			if present == 0 and past == 0:
				ans = -1
				break
			elif present == 1 and past == 1:
				ans += 5
			elif present == 1 and past == 0:
				ans += 1
		elif a[i] == 1:
			ans += 1
	answers.append(ans)
for i in range(kolvo):
	print(answers[i])


ans = []
k = int(input())
while k > 0:
	n = int(input())
	s = list(map(int, input().split()))
	L = 1
	d = 0
	for i in range(n):
		if s[i] == 1:
			if i - 1 >= 0 and s[i - 1] == 1:
				L += 5
			else:
				L += 1
			d = 0
		else:
			d += 1
		if d == 2:
			ans += [-1]
			break
	if d != 2:
		ans += [L]
	k -= 1
print(*ans, sep='\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	sum = 1
	if a[0] == 0:
		pass
	elif a[0] == 1:
		sum += 1
	for i in range(1, n):
		if a[i] == 0 and a[i - 1] == 0:
			sum = -1
			break
		elif a[i] == 1 and a[i - 1] == 1:
			sum += 5
		elif a[i] == 1 and a[i - 1] == 0:
			sum += 1
	print(sum)


def flower(n, a):
	state = 2
	length = 1
	condition = 0
	for i in range(n):
		if a[i] == 0:
			state -= 1
			condition = 0
			if state == 0:
				return -1
		else:
			if condition == 1:
				length += 5
			else:
				condition = 1
				length += 1
			state = 2
	return length
t = int(input())
b = []
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b.append(flower(n, a))
for i in range(len(b)):
	print(b[i])


a = int(input())
for i in range(a):
	n = int(input())
	k = 1
	sp = [int(q) for q in input().split()]
	for z in range(n):
		if z == 0:
			if sp[z] == 1:
				k += 1
		elif sp[z] == 0 and sp[z - 1] == 0:
			k = -1
			break
		elif sp[z] == sp[z - 1]:
			k += 5
		elif sp[z] == 1:
			k += 1
	print(k)


st1 = int(input())
st2 = []
rez = [1] * st1
k = 0
for i in range(st1 * 2):
	a = []
	st2.append(input())
	if i % 2 == 1:
		st2[i] = st2[i].replace(' ', '')
		if '00' in st2[i]:
			rez[k] = -1
		else:
			for n in range(len(st2[i])):
				st2[i] += '0'
				if st2[i][n] == '1' and st2[i][n - 1] == '1':
					rez[k] += 5
				elif st2[i][n] == '1':
					rez[k] += 1
		k += 1
for i in rez:
	print(i)


for t in range(int(input())):
	n = int(input())
	lst = input().split()
	c = 0
	L = 1
	out = 0
	for day in lst:
		if day == '1':
			c += 1
			out = 0
		else:
			out += 1
			c = 0
		if c == 1:
			L += 1
		elif c > 1:
			L += 5
		elif out >= 2:
			print(-1)
			break
	if out < 2:
		print(L)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	h = 1
	if a[0] == 1:
		h += 1
	for i in range(1, n):
		if a[i] == 1 and a[i - 1] == 1:
			h += 5
		elif a[i] == 1 and a[i - 1] == 0:
			h += 1
		elif a[i] == 0 and a[i - 1] == 0:
			h = -1
			break
	print(h)


for i in range(int(input())):
	n = int(input())
	ans = 1
	arr = list(map(int, input().strip().split()))
	f = 1
	for i in range(1, len(arr)):
		if arr[i] == 1:
			if arr[i - 1] == 1:
				ans += 5
			else:
				ans += 1
		if arr[i] == 0:
			if arr[i - 1] == 0:
				ans = -1
				f = 0
				break
	if f == 1:
		ans += 1 if arr[0] == 1 else 0
	print(ans)


t = int(input())
for z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 1
	if l[0] == 1:
		ans += 1
	die = 0
	for i in range(1, n):
		if l[i] == 0 and l[i - 1] == 0:
			die = 1
			ans = -1
			break
		if l[i] == 1:
			if l[i - 1] == 0:
				ans += 1
			else:
				ans += 5
	print(ans)


for _ in range(int(input())):
	(n, a) = (int(input()), list(map(int, input().split())))
	ans = 1 + a[0]
	for i in range(1, n):
		if a[i] == 0 and a[i - 1] == 0:
			ans = -1
			break
		if a[i] == 0:
			continue
		ans += 5 if a[i - 1] == 1 else 1
	print(ans)


h = 1
x = 0
y = 0
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	for j in range(n):
		if a[j] == 0:
			y = 0
			x += 1
		elif a[j] == 1:
			y += 1
			h += 1
			x = 0
		if x >= 2:
			print(-1)
			break
		if y >= 2:
			h += 4
	if x < 2:
		print(h)
	x = 0
	y = 0
	h = 1


def solve(n, watering):
	if '00' in watering:
		return -1
	height = 1
	for i in range(n):
		if watering[i] == '0':
			continue
		if i > 0 and watering[i - 1] == '1':
			height += 4
		height += 1
	return height
ans = []
for _ in range(int(input())):
	ans.append(solve(int(input()), ''.join(list(input().split()))))
print(*ans, sep='\n')


for t in range(int(input())):
	n = int(input())
	flag = 1
	grow = 1
	s = list(map(int, input().split()))
	for i in range(n):
		if s[i] == 1:
			if i >= 1:
				if s[i - 1] == 1:
					grow += 5
				else:
					grow += 1
			else:
				grow += 1
		elif i < n - 1:
			if s[i + 1] == 0:
				flag = 0
				break
	if flag == 1:
		print(grow)
	else:
		print(-1)


t = int(input())
for i in range(t):
	flag = True
	count = 1
	n = int(input())
	s = input().split()
	if len(s) != 1:
		for j in range(len(s)):
			if j != len(s) - 1:
				if s[j] == '0' and s[j + 1] == '0':
					flag = False
					print(-1)
					break
		for j in range(len(s)):
			if s[j] == '1':
				if s[j - 1] == '1' and j != 0:
					count += 5
				else:
					count += 1
		if flag:
			print(count)
	elif s[0] == '1':
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	plant = 1
	boosting = 0
	die = 0
	for i in arr:
		if i == 1:
			die = 0
			if boosting == 0:
				plant += 1
				boosting = 1
			else:
				plant += 5
		elif die == 1:
			plant = -1
			break
		else:
			boosting = 0
			die = 1
	print(plant)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	h = 1
	if l[0] == 1:
		h = 2
	else:
		h = 1
	for i in range(1, len(l)):
		if l[i] == 1 and l[i - 1] == 1:
			h += 5
		if l[i] == 1 and l[i - 1] == 0:
			h += 1
		if l[i] == 0 and l[i - 1] == 1:
			h += 0
		if l[i] == 0 and l[i - 1] == 0:
			h = -1
			break
	print(h)
	t -= 1


for s in [*open(0)][2::2]:
	print((sum((max(0, 5 * l - 4) for l in map(len, s[::2].split('0')))) + 1, -1)['0 0' in s])


import math

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

def stringlsit():
	return input().split(' ')

def solve():
	n = int(input())
	a = intlist()
	t = 0
	w = True
	for i in a:
		if i == 1 and t == 0:
			t += 1
			w = True
			continue
		if i == 1 and t != 0 and w:
			t += 5
			continue
		if i == 1 and t != 0 and (not w):
			t += 1
			w = True
			continue
		if i == 0 and w:
			w = False
			continue
		return -1
	return t + 1
	return ans
t = input()
for tt in range(int(t)):
	print(solve())


def solution(lst):
	watered_yesterday = None
	height = 1
	for watered in lst:
		if watered:
			if watered_yesterday:
				height += 5
				_hy_anon_var_1 = None
			else:
				height += 1
				_hy_anon_var_1 = None
			_hy_anon_var_3 = _hy_anon_var_1
		else:
			if not watered_yesterday is None and (not watered_yesterday):
				return -1
				_hy_anon_var_2 = None
			else:
				_hy_anon_var_2 = None
			_hy_anon_var_3 = _hy_anon_var_2
		watered_yesterday = watered
	return height
t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solution(lst))


def solve(n, arr):
	curr = 1
	for (i, v) in enumerate(arr):
		if v == 0:
			if i == 0 or arr[i - 1] == 1:
				continue
			return -1
		elif i == 0 or arr[i - 1] == 0:
			curr += 1
		else:
			curr += 5
	return curr
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


t = int(input())
for i in range(t):
	a = int(input())
	x = list(input().split())
	y = ''.join(map(str, x))
	s = 0
	if y.count('00'):
		print(-1)
	else:
		for j in range(len(y)):
			if j < len(y) - 1 and (y[j] == '1' and y[j + 1] == '1'):
				s += 5
			elif y[j] == '1':
				s += 1
		print(s + 1)


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def solve() -> None:
	n = int(input())
	a = list(map(int, input().split()))
	h = 1 + a[0]
	for i in range(1, n):
		if a[i] == a[i - 1] == 0:
			h = -1
			break
		if a[i - 1] == a[i] == 1:
			h += 5
		elif a[i] == 1:
			h += 1
	print(h)

def main() -> None:
	t = int(input())
	for _ in range(t):
		solve()
main()


for s in [*open(0)][2::2]:
	print((sum((max(0, 5 * len(x) - 4) for x in s[::2].split('0'))) + 1, -1)['0 0' in s])


n = int(input())
for i in range(n):
	ar = []
	height = 1
	watered = None
	leng = int(input())
	ar = [int(x) for x in input().split()]
	for i in ar:
		if i == 1 and watered == None:
			height += 1
			watered = True
		elif i == 0 and watered == None:
			watered = False
		elif i == 1 and watered == False:
			watered = True
			height += 1
		elif i == 1 and watered == True:
			height += 5
			watered = True
		elif i == 0 and watered == True:
			watered = False
		elif i == 0 and watered == False:
			height = -1
			break
	print(height)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	assert len(a) == n
	h = 1
	if a[0] == 1:
		h += 1
	for i in range(1, n):
		if a[i - 1] == a[i] == 0:
			print(-1)
			break
		if a[i] == 1:
			if a[i - 1] == 1:
				h += 5
			else:
				h += 1
	else:
		print(h)


t = int(input())
while t > 0:
	n = int(input())
	s = input().split()
	flag = 1
	long = 1
	if s[0] == '1':
		long = long + 1
	for i in range(1, len(s)):
		if s[i] == '1' and s[i - 1] == '1':
			long = long + 5
		elif s[i] == '1' and s[i - 1] == '0':
			long = long + 1
		elif s[i] == '0' and s[i - 1] == '0':
			flag = 0
			break
	if flag == 0 and len(s) > 0:
		print(-1)
	if flag == 1 and len(s) > 0:
		print(long)
	t = t - 1


n = int(input())
for a in range(n):
	nn = int(input())
	nnl = [int(item) for item in input().split()]
	flower_tall = 1
	inp_prev = -1
	for inp in nnl:
		if inp == 1 and inp_prev == 1:
			flower_tall += 5
		elif inp == 1:
			flower_tall += 1
		elif inp == 0 and inp_prev == 0:
			flower_tall = -1
			break
		inp_prev = inp
	print(flower_tall)


for _ in range(int(input())):
	n = int(input())
	w = 100
	h = 1
	for x in map(int, input().split()):
		if x:
			if w == 1:
				h += 5
			else:
				h += 1
		elif not w:
			print(-1)
			break
		w = x
	else:
		print(h)


for _ in range(int(input())):
	a = int(input())
	h = 1
	b = list(map(int, input().split()))
	if b[0] == 1:
		h += 1
	for i in range(1, a):
		if b[i] == 1:
			if b[i - 1] == 1:
				h += 5
			else:
				h += 1
		elif b[i] == 0:
			if b[i - 1] == 0:
				h = -1
				break
	print(h)


t = int(input())
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	f = 0
	f1 = 0
	x = 0
	count = 1
	if arr[0] == 1:
		count += 1
		f1 = 1
	else:
		f = 1
	for j in range(1, n):
		if arr[j] == 1 and f1 == 1:
			count += 5
			f = 0
		elif arr[j] == 1 and f1 == 0:
			count += 1
			f1 = 1
			f = 0
		elif arr[j] == 0 and f == 1:
			x = 1
			break
		else:
			f1 = 0
			f = 1
	if x == 1:
		print('-1')
	else:
		print(count)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	h = 1
	p = -1
	for i in a:
		if i == 1:
			if p == 1:
				h += 5
			else:
				h += 1
		elif p == 0:
			print(-1)
			break
		p = i
	else:
		print(h)