You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $n$ bosses in this tower, numbered from $1$ to $n$. The type of the $i$-th boss is $a_i$. If the $i$-th boss is easy then its type is $a_i = 0$, otherwise this boss is hard and its type is $a_i = 1$.

During one session, either you or your friend can kill one or two bosses (neither you nor your friend can skip the session, so the minimum number of bosses killed during one session is at least one). After your friend session, your session begins, then again your friend session begins, your session begins, and so on. The first session is your friend's session.

Your friend needs to get good because he can't actually kill hard bosses. To kill them, he uses skip points. One skip point can be used to kill one hard boss.

Your task is to find the minimum number of skip points your friend needs to use so you and your friend kill all $n$ bosses in the given order.

For example: suppose $n = 8$, $a = [1, 0, 1, 1, 0, 1, 1, 1]$. Then the best course of action is the following:

  your friend kills two first bosses, using one skip point for the first boss;  you kill the third and the fourth bosses;  your friend kills the fifth boss;  you kill the sixth and the seventh bosses;  your friend kills the last boss, using one skip point, so the tower is completed using two skip points. 

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of bosses. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 1$), where $a_i$ is the type of the $i$-th boss.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer: the minimum number of skip points your friend needs to use so you and your friend kill all $n$ bosses in the given order.


-----Example-----
Input
6
8
1 0 1 1 0 1 1 1
5
1 1 1 1 0
7
1 1 1 1 0 0 1
6
1 1 1 1 1 1
1
1
1
0

Output
2
2
2
2
1
0

Source: codeforces | Difficulty: MEDIUM
Tags: Greedy algorithms

Dynamic programming

Graph algorithms

Shortest paths


Solutions:
t = int(input())
for i in range(0, t):
	n = int(input())
	a = input()
	print(int(a[0]) + a[1:].count('1 1 1'))


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	n += 1
	dp = [[float('inf'), float('inf')] for i in range(n)]
	dp[0][0] = 0
	for i in range(n):
		for turn in [0, 1]:
			c = (turn + 1) % 2
			if i + 1 < n:
				dp[i + 1][(1 + turn) % 2] = min(dp[i + 1][(1 + turn) % 2], dp[i][turn] + c * arr[i])
			if i + 2 < n:
				dp[i + 2][(1 + turn) % 2] = min(dp[i + 2][(1 + turn) % 2], dp[i][turn] + c * arr[i] + c * arr[i + 1])
	print(min(dp[-1]))
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')
for _ in range(int(input())):
	main()


def answer(n, A):
	count = 0
	if A[0] == 1:
		count += 1
	count1 = 0
	for i in range(1, n):
		if A[i] == 1:
			count1 += 1
		else:
			count += count1 // 3
			count1 = 0
	count += count1 // 3
	return count
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(answer(n, arr))


import sys
from collections import deque, defaultdict, namedtuple
import heapq
from math import sqrt, factorial, gcd, ceil, atan, pi

def input():
	return sys.stdin.readline()[:-1]
import string
import operator
import random
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1000000000.0) + 7
INF = float('inf')

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	if n == 1:
		print(a[0])
		return
	dp = [[INF, INF] for _ in range(n)]
	dp[0][0] = a[0]
	dp[1][0] = a[0] + a[1]
	for i in range(1, n):
		dp[i][1] = min(dp[i][1], dp[i - 1][0])
		if i > 1:
			dp[i][1] = min(dp[i][1], dp[i - 2][0])
		dp[i][0] = min(dp[i][0], dp[i - 1][1] + a[i])
		if i > 1:
			dp[i][0] = min(dp[i][0], dp[i - 2][1] + a[i - 1] + a[i])
	print(min(dp[n - 1]))
T = 1
T = int(input())
for case in range(1, T + 1):
	ans = solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	ans = 0
	while i < n:
		if a[i] == 1:
			ans += 1
		if i + 1 < n and a[i + 1] == 0:
			i += 1
		elif i + 2 < n and a[i + 2] == 1:
			i += 3
		else:
			i += 2
	print(ans)


def sol(n, a):
	dp = [[a[0]] + [0] * (n - 1) for _ in range(2)]
	for idx in range(1, n):
		for player in range(2):
			choices = [dp[not player][idx - 1]]
			if idx > 1:
				choices.append(dp[not player][idx - 2] + a[idx - 1] * player)
			dp[player][idx] = min(choices) + a[idx] * player
	return min(dp[1][-1], dp[0][-1])

def main():
	T = int(input())
	for t in range(T):
		n = int(input())
		a = list(map(int, input().split()))
		print(sol(n, a))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = ''.join(list(input().split()))
	ans = 0
	if s[0] == '1':
		ans += 1
	i = 1
	while True:
		if s[i:i + 3] == '111':
			ans += 1
			i += 3
		else:
			i += 1
		if i > n - 3:
			break
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	if a[0] == 1:
		k = 1
	i = 1
	while i < n:
		if a[i] == 1:
			j = i
			while j < n and a[j] == 1:
				j += 1
			k += (j - i) // 3
			i = j
		else:
			i += 1
	print(k)


INF = float('inf')
it = lambda : list(map(int, input().strip().split()))

def solve():
	n = int(input())
	a = it()
	if n == 1:
		return int(a[0] == 1)
	dp = [[n] * 2 for _ in range(n)]
	dp[0][0] = int(a[0] == 1)
	dp[1][0] = int(a[0] == 1) + int(a[1] == 1)
	dp[1][1] = int(a[0] == 1)
	for i in range(2, n):
		dp[i][0] = min(dp[i][0], dp[i - 1][1] + int(a[i] == 1))
		dp[i][0] = min(dp[i][0], dp[i - 2][1] + int(a[i] == 1) + int(a[i - 1] == 1))
		dp[i][1] = min(dp[i][1], dp[i - 1][0])
		dp[i][1] = min(dp[i][1], dp[i - 2][0])
	return min(dp[n - 1])
T = int(input())
for _ in range(T):
	print(solve())


Max = float('inf')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[-1, -1] for i in range(n)]

	def solve(i, n, k):
		if n == 1:
			return a[0]
		dp[0][0] = a[0]
		dp[0][1] = Max
		dp[1][0] = a[0] + a[1]
		dp[1][1] = a[0]
		for i in range(2, n):
			dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1])
			dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
		return min(dp[n - 1])
	ans = solve(0, n, 0)
	print(ans)


for s in [*open(0)][2::2]:
	a = s.split()
	print((a[0] == '1') + ''.join(a[1:]).count('111'))


entrada = int(input())
for i in range(entrada):
	n_boss = int(input())
	bosses = [int(x) for x in input().split()]
	n_skips = bosses[0]
	seq = 0
	for j in range(1, n_boss):
		if bosses[j] == 1:
			seq += 1
		else:
			n_skips += seq // 3
			seq = 0
	n_skips += seq // 3
	print(n_skips)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = f = 0
	if a[0] == 1:
		c = 1
	ans = 0
	i = 1
	while i < n:
		if a[i] == 1:
			if f == 0:
				i += 1
				f = 1
				continue
			if f == 1:
				i += 1
				f = 2
				continue
			if f == 2:
				c += 1
				i += 1
				f = 0
				continue
		if a[i] == 0:
			f = 0
		i += 1
	print(c)


from sys import stdin, exit
from typing import List, Tuple
tests = int(stdin.readline().rstrip())
test_cases: List[List[int]] = [None] * tests

def min_tokens(arr: List[int]) -> int:
	if len(arr) == 1:
		return arr[0]
	min_tokens: List[List[int]] = [[0, 0] for i in range(len(arr))]
	min_tokens[0][0] = arr[0]
	min_tokens[0][1] = float('inf')
	min_tokens[1][0] = arr[0] + arr[1]
	min_tokens[1][1] = arr[0]
	for i in range(2, len(min_tokens)):
		min_tokens[i][0] = min(min_tokens[i - 1][1] + arr[i], min_tokens[i - 2][1] + arr[i - 1] + arr[i])
		min_tokens[i][1] = min(min_tokens[i - 1][0], min_tokens[i - 2][0])
	return min(min_tokens[-1][0], min_tokens[-1][1])
for i in range(tests):
	stdin.readline()
	test_cases[i] = [int(v) for v in stdin.readline().rstrip().split()]
for case in test_cases:
	print(min_tokens(case))


import sys
import math as mt
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	dp = [[n + n for j in range(2)] for i in range(n)]
	dp[0][0] = 0
	if l[0] == 1:
		dp[0][0] = 1
	if n > 1:
		dp[1][0] = dp[0][0]
		if l[1] == 1:
			dp[1][0] += 1
		dp[1][1] = dp[0][0]
	for i in range(2, n):
		ex = 0
		if l[i] == 1:
			ex = 1
		dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + ex
		dp[i][1] = min(dp[i - 2][0], dp[i - 1][0])
	print(min(dp[n - 1][1], dp[n - 1][0]))


from collections import defaultdict
for i in range(int(input())):
	n = int(input())
	l = tuple(map(int, input().split()))
	dp1 = defaultdict(lambda : 10 ** 12)
	dp2 = defaultdict(lambda : 10 ** 12)
	dp1[0, 1] = l[0]
	dp2[1, 1] = l[0]
	for i in range(1, n):
		dp1[i, 1] = min(dp2[i - 1, 1], dp2[i - 1, 2]) + l[i]
		dp1[i, 2] = dp1[i - 1, 1] + l[i]
		dp2[i, 1] = min(dp1[i - 1, 1], dp1[i - 1, 2])
		dp2[i, 2] = dp2[i - 1, 1]
	print(min((min(dp1[n - 1, j], dp2[n - 1, j]) for j in [1, 2])))


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	c = 0
	skips = 0
	i = 0
	while i < n:
		if c == 0:
			if arr[i] == 1:
				if i + 1 < n and arr[i + 1] == 0 and (i + 2 < n) and (arr[i + 2] == 1):
					i += 2
				else:
					i += 1
				skips += 1
			else:
				if i + 2 < n and arr[i + 2] == 1 and (arr[i + 1] == 0):
					i += 1
				i += 1
			c = 1
		else:
			if i + 1 < n and arr[i + 1] == 1:
				i += 2
			else:
				i += 1
			c = 0
	print(skips)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	(x, i) = (0, 0)
	while i < n:
		if x == 0:
			if i < n and l[i]:
				count += 1
			i += 1
			if i < n - 1 and (not l[i]) and l[i + 1]:
				i += 1
			x = 1
		else:
			i += 1
			if i < n and l[i]:
				i += 1
			x = 0
	print(count)


import math
t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	dp = []
	for w in range(n):
		dp.append([[float('inf'), float('inf')], [float('inf'), float('inf')]])
	if b[0] == 1:
		dp[0][0][0] = 1
	else:
		dp[0][0][0] = 0
	j = 1
	while j < n:
		if b[j] == 1:
			dp[j][0][0] = min(dp[j][0][0], min(dp[j - 1][1]) + 1)
			dp[j][0][1] = dp[j - 1][0][0] + 1
			dp[j][1][0] = min(dp[j][0][1], min(dp[j - 1][0]))
			dp[j][1][1] = dp[j - 1][1][0]
		else:
			dp[j][0][0] = min(dp[j][0][0], min(dp[j - 1][1]))
			dp[j][0][1] = dp[j - 1][0][0]
			dp[j][1][0] = min(dp[j][0][1], min(dp[j - 1][0]))
			dp[j][1][1] = dp[j - 1][1][0]
		j += 1
	print(min(min(dp[n - 1][0]), min(dp[n - 1][1])))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(c) for c in input().split()]
	dp = [-1 for i in range(n)]
	dp1 = [-1 for i in range(n)]
	dp[-1] = 0
	dp1[-1] = arr[-1]
	dp.append(0)
	dp1.append(0)
	for i in range(n - 2, -1, -1):
		dp[i] = min(dp1[i + 1], dp1[i + 2])
		dp1[i] = min(arr[i] + dp[i + 1], arr[i] + arr[i + 1] + dp[i + 2])
	print(dp1[0])


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	a = list(map(int, input().split()))
	ukazatel = 1
	count = 0
	pred = a[0]
	while ukazatel < n:
		if a[ukazatel] == 1:
			count += 1
		else:
			ans += count // 3
			count = 0
		ukazatel += 1
	ans += count // 3
	if a[0] == 1:
		ans += 1
	print(ans)


for t in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	count = 0
	ans = 0
	if a[0] == 1:
		ans += 1
	a.pop(0)
	for i in range(l - 1):
		if a[i] == 1:
			count += 1
		else:
			ans += count // 3
			count = 0
	ans += count // 3
	print(ans)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	INF = 1000000
	aa = [int(a) for a in inputi().split()]
	(p1, p2, f1, f2) = (INF, 0, INF, INF)
	for a in aa:
		(p1, p2, f1, f2) = (min(f1, f2), p1, min(p1, p2) + a, f1 + a)
	print(min(p1, p2, f1, f2))

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	dp = [[0, 0] for i in range(n)]
	if n == 1:
		print(a[0])
		continue
	dp[0][0] = a[0]
	dp[0][1] = 10 ** 18
	dp[1][0] = a[0] + a[1]
	dp[1][1] = a[0]
	for i in range(2, n):
		dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	print(min(dp[n - 1][0], dp[n - 1][1]))


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


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[1 << 30 for _ in range(2)] for _ in range(n + 1)]
	(dp[1][0], dp[1][1]) = (a[0], a[0])
	for i in range(2, n + 1):
		dp[i][0] = min(dp[i][0], dp[i - 1][1] + a[i - 1], dp[i - 2][1] + a[i - 1] + a[i - 2])
		dp[i][1] = min(dp[i][1], dp[i - 1][0], dp[i - 2][0])
	print(min(dp[n][0], dp[n][1]))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	A.append(0)
	A.append(0)
	DP0 = [1 << 30] * (n + 3)
	DP1 = [1 << 30] * (n + 3)
	DP0[0] = 0
	for i in range(n):
		if A[i] == 0 and A[i + 1] == 0:
			DP1[i + 1] = min(DP1[i + 1], DP0[i])
			DP1[i + 2] = min(DP1[i + 2], DP0[i])
		elif A[i] == 0 and A[i + 1] == 1:
			DP1[i + 1] = min(DP1[i + 1], DP0[i])
			DP1[i + 2] = min(DP1[i + 2], DP0[i] + 1)
		elif A[i] == 1 and A[i + 1] == 0:
			DP1[i + 1] = min(DP1[i + 1], DP0[i] + 1)
			DP1[i + 2] = min(DP1[i + 2], DP0[i] + 1)
		elif A[i] == 1 and A[i + 1] == 1:
			DP1[i + 1] = min(DP1[i + 1], DP0[i] + 1)
			DP1[i + 2] = min(DP1[i + 2], DP0[i] + 2)
		DP0[i + 1] = min(DP0[i + 1], DP1[i])
		DP0[i + 2] = min(DP0[i + 2], DP1[i])
	print(min(DP0[n], DP1[n]))


for _ in range(int(input())):
	n = int(input())
	arr = input().strip()
	print(int(arr[0]) + arr[1:].count('1 1 1'))


from sys import stdin, stdout
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

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

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

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0
for _ in range(int(inp())):
	n = int(inp())
	arr = lmp()
	k = 1 if arr[0] == 1 else 0
	if n == 1:
		print(k)
		continue
	c = 0
	for i in range(1, n):
		if arr[i] == 0 and c != 0:
			k += c // 3
			c = 0
		if arr[i] == 1:
			c += 1
	if c != 0:
		k += c // 3
	print(k)


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = [0] * T
for t in range(T):
	N = int(input())
	A = list(map(int, input().split())) + [0]
	dp1 = [0] + [float('inf')] * (N + 4)
	dp2 = [float('inf')] * (N + 5)
	for i in range(N):
		dp2[i + 1] = min(dp1[i] + A[i], dp2[i + 1])
		dp2[i + 2] = min(dp1[i] + A[i] + A[i + 1], dp2[i + 2])
		dp1[i + 1] = min(dp2[i], dp1[i + 1])
		dp1[i + 2] = min(dp2[i], dp1[i + 2])
	ans[t] = min(dp1[N], dp2[N])
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	bosses = list(map(int, input().split()))
	if bosses[0] == 1:
		cnt = 1
	else:
		cnt = 0
	index = 1
	while index + 2 < n:
		if bosses[index] == bosses[index + 1] == bosses[index + 2] == 1:
			cnt += 1
			index += 3
		else:
			index += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dpm = [0] * n
	dpf = [0] * n
	dpm[n - 1] = dpm[n - 2] = 0
	dpf[n - 1] = a[n - 1]
	dpf[n - 2] = a[n - 2]
	for i in reversed(range(n - 2)):
		dpm[i] = min(dpf[i + 1], dpf[i + 2])
		dpf[i] = min(dpm[i + 1] + a[i], dpm[i + 2] + a[i] + a[i + 1])
	print(dpf[0])


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = []
	b = 0
	f = A[0]
	for a in A:
		if a == f:
			b += 1
		else:
			B.append(b)
			b = 1
			f = a
	B.append(b)
	s = 0
	f = A[0]
	t = True
	for j in range(len(B)):
		if B[j] == 0:
			f = 1 - f
			continue
		if f == 0 and t:
			t = False
		elif f == 0 and (not t):
			if B[j] == 1:
				t = True
		elif f == 1 and t:
			s += (B[j] + 2) // 3
			if B[j] != 1:
				t = True
			elif j < len(B) - 1:
				if B[j + 1] == 1:
					B[j + 1] -= 1
					t = False
				else:
					t = True
		elif f == 1 and (not t):
			s += B[j] // 3
			t = True
		f = 1 - f
	print(s)


l = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = []
	count = 1
	e = a[0]
	for i in range(1, n):
		if a[i] == e:
			count = count + 1
		else:
			s.append([e, count])
			e = a[i]
			count = 1
	s.append([e, count])
	if s[0][0] == 0:
		chance = 'f'
		count = 0
		for i in s:
			if chance == 'f':
				if i[0] == 0:
					chance = 'm'
			else:
				count = count + i[1] // 3
				chance = 'f'
	else:
		chance = 'f'
		if s[0][1] % 3 == 0:
			count = s[0][1] // 3
		else:
			count = s[0][1] // 3 + 1
		s = s[1:]
		for i in s:
			if chance == 'f':
				if i[0] == 0:
					chance = 'm'
			else:
				count = count + i[1] // 3
				chance = 'f'
	l.append(count)
for i in l:
	print(i)


def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import math

def solve():
	N = getInt()
	A = getInts()
	dp = [[0 for j in range(2)] for n in range(N + 1)]
	dp[1][0] = A[0]
	dp[1][1] = 10 ** 18
	if N <= 3:
		print(A[0])
		return
	dp[2][0] = A[0] + A[1]
	dp[2][1] = A[0]
	dp[3][0] = dp[2][1] + A[2]
	dp[3][1] = A[0]
	for n in range(4, N + 1):
		dp[n][0] = min(dp[n - 1][1] + A[n - 1], dp[n - 2][1] + A[n - 1] + A[n - 2])
		dp[n][1] = min(dp[n - 2][0], dp[n - 1][0])
	print(min(dp[N][0], dp[N][1]))
T = getInt()
for t in range(T):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	lst = input().strip()
	k = lst[1:].count('1 1 1')
	print(k + int(lst[0]))


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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from collections import deque
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[10 ** 18] * 4 for __ in range(n + 1)]
	dp[0] = [10 ** 18, 10 ** 18, 0, 0]
	for i in range(n):
		if i == 0:
			dp[i + 1] = [a[i], a[i], 10 ** 16, 10 ** 16]
			continue
		dp[i + 1][0] = min(dp[i][2], dp[i][3]) + a[i]
		dp[i + 1][1] = min(dp[i - 1][2], dp[i - 1][3]) + a[i - 1] + a[i]
		dp[i + 1][2] = min(dp[i][0], dp[i][1])
		dp[i + 1][3] = min(dp[i - 1][0], dp[i - 1][1])
	print(min(dp[n]))


import math
noOfTestCases = int(input())
for testCase in range(noOfTestCases):
	arrSiz = int(input())
	arr = [int(i) for i in input().split()]
	dp = {}
	dp[0, 0] = arr[0] == 1
	dp[0, 1] = math.inf
	if arrSiz > 1:
		dp[1, 0] = (arr[0] == 1) + (arr[1] == 1)
		dp[1, 1] = dp[0, 0]
	for i in range(2, arrSiz):
		dp[i, 0] = min(dp[i - 2, 1] + (arr[i - 1] == 1) + (arr[i] == 1), dp[i - 1, 1] + (arr[i] == 1))
		dp[i, 1] = min(dp[i - 2, 0], dp[i - 1, 0])
	print(int(min(dp[arrSiz - 1, 0], dp[arrSiz - 1, 1])))


from sys import *
from math import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = 0
	f = i = 0
	while i < n:
		x = 0
		if f == 0:
			x += 1
			if a[i] == 1:
				ans += 1
			if i + 2 < n:
				if a[i + 1] == 0 and a[i + 2] == 1:
					x += 1
		if f == 1:
			x += 1
			if i + 1 < n:
				if a[i + 1] == 1:
					x += 1
		i += x
		f = (f + 1) % 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 0
	t = 0
	ans = 0
	while True:
		if i == n - 1 or i == n - 2:
			if t == 1:
				print(ans)
				break
			elif arr[i] == 0:
				print(ans)
				break
			else:
				print(ans + 1)
				break
		if t == 0:
			if arr[i + 1] == 1:
				ans += arr[i]
				i += 1
				t = 1
				continue
			elif i + 2 < n:
				if arr[i + 2] == 0:
					ans += arr[i]
					i += 1
					t = 1
					continue
				else:
					ans += arr[i]
					i += 2
					t = 1
					continue
			else:
				ans += arr[i]
				i += 2
				t = 1
				continue
		if t == 1:
			if arr[i + 1] == 1:
				i += 2
				t = 0
				continue
			if arr[i + 1] == 0:
				i += 1
				t = 0
				continue


from sys import stdin, stdout
from math import gcd, sqrt, inf
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
M = inf
for _ in range(I()):
	n = I()
	a = L() + [0]
	p = 0
	ans = a.pop(0)
	for i in range(n):
		if a[i] == 1:
			p += 1
		elif p:
			ans += p // 3
			p = 0
	print(ans)


def solve():
	N = int(input())
	A = [int(x) for x in input().split()]
	dp = [[0, 0] for _ in range(N)]
	if N == 1:
		return A[0]
	if N == 2:
		return min(A[0], A[0] + A[1])
	dp[0][0] = A[0]
	dp[1][0] = A[0] + A[1]
	dp[0][1] = 10 ** 10
	dp[1][1] = A[0]
	for i in range(2, N):
		dp[i][0] = min(dp[i - 1][1] + A[i], dp[i - 2][1] + A[i - 1] + A[i])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	return min(dp[N - 1])
tc = int(input())
for _ in range(tc):
	print(solve())


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(0)
	add = 0
	b = []
	c = 0
	for i in range(n + 1):
		if a[i] == 1:
			add += 1
		else:
			b.append(add)
			c += 1
			add = 0
	(count, t, r) = (0, 0, 0)
	for i in range(c):
		if a[i] == 1 and i == 0:
			t = b[i] // 3
			r = b[i] % 3
			if r == 0:
				count += t
			else:
				count += t + 1
		else:
			t = b[i] // 3
			count += t
	print(count)


import sys
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, ar) = (int(input()), list(map(int, input().split())))
	(first, cc, res) = (1, 0, 0)
	for i in range(n):
		cc += 1
		if i + 1 < n and ar[i] == ar[i + 1]:
			continue
		if ar[i] == 1:
			res += (cc + 2) // 3 if first else cc // 3
		(cc, first) = (0, 0)
	print(res)


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
from time import time
sys.setrecursionlimit(10 ** 6)
MOD = 998244353

def main():
	dp = [[0] * (2 * 10 ** 5 + 5) for i in range(2)]
	ans = []
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		for i in range(2):
			for j in range(n + 1):
				dp[i][j] = 0
		dp[1][0] = dp[0][0] = arr[0]
		for i in range(1, n):
			for j in range(2):
				if j:
					dp[j][i] = min([10 ** 9, dp[j - 1][i - 2] + arr[i] + arr[i - 1]][i > 1], dp[j - 1][i - 1] + arr[i])
				else:
					dp[j][i] = min([10 ** 9, dp[j + 1][i - 2]][i > 1], dp[j + 1][i - 1])
		ans.append(str(min(dp[1][n - 1], dp[0][n - 1])))
	print('\n'.join(ans))
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	cnt = 0
	if a[0] == '1':
		cnt += 1
	a = ''.join(a[1:])
	print(cnt + a.count('111'))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	k = ''
	for i in A:
		k += str(i)
	A = k
	if A[0] == '1':
		ans += 1
	ans += A[1:].count('111')
	print(ans)


import sys
y = sys.stdin.readline
for _ in range(int(y())):
	n = int(y())
	a = [*map(int, y().split())][::-1]
	m = [(0, 0), (0, a[0])]
	for i in range(2, n + 1):
		m.append((min(m[-1][1], m[-2][1]), min(m[-1][0] + a[i - 1], m[-2][0] + a[i - 1] + a[i - 2])))
	print(m[-1][1])


from math import *
from sys import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	m = 0
	i = 0
	if a[0] == 1:
		ans = ans + 1
	b = []
	i = 1
	c = 0
	while i < n:
		if a[i] == 1:
			c = c + 1
			if c == 3:
				ans = ans + 1
				c = 0
		else:
			c = 0
		i = i + 1
	print(ans)


INF = 1000000000

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	dp = []
	for i in range(0, 2):
		dp.append([INF for x in range(0, n + 1)])
	dp[0][0] = 0
	dp[1][0] = INF
	for i in range(1, n + 1):
		if i == 1:
			dp[0][i] = dp[1][i - 1]
		else:
			dp[0][i] = min(dp[1][i - 1], dp[1][i - 2])
		if i == 1:
			dp[1][i] = dp[0][i - 1] + (1 if a[i - 1] == 1 else 0)
		else:
			dp[1][i] = min(dp[0][i - 1] + (1 if a[i - 1] == 1 else 0), dp[0][i - 2] + (1 if a[i - 2] == 1 else 0) + (1 if a[i - 1] == 1 else 0))
	print(min(dp[0][n], dp[1][n]))
t = int(input())
for tt in range(0, t):
	solve()


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(*a)
		continue
	dp = []
	l = [2 * 10 ** 5, 2 * 10 ** 5]
	for i in range(n):
		dp.append(l.copy())
	dp[0][0] = a[0]
	dp[1][0] = a[1] + a[0]
	dp[1][1] = dp[0][0]
	for i in range(2, n):
		dp[i][0] = a[i] + min(dp[i - 1][1], dp[i - 1][0])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	print(min(dp[n - 1][0], dp[n - 1][1]))


for _ in range(int(input())):
	ni = int(input())
	arr1 = list(map(int, input().split()))
	count1 = 0
	if arr1[0] == 1:
		count1 += 1
	i = 2
	while i < len(arr1) - 1:
		if arr1[i - 1] == 1 and arr1[i] == 1 and (arr1[i + 1] == 1):
			count1 += 1
			i += 3
		else:
			i += 1
	print(count1)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def solve():
	n = iin()
	l = lin()
	dp = [[float('infinity')] * (n + 1), [float('infinity')] * (n + 1)]
	dp[0][0] = 0
	dp[0][1] = dp[1][0]
	dp[1][1] = dp[0][0] + l[0]
	for i in range(1, n):
		dp[0][i + 1] = min(dp[1][i - 1], dp[1][i])
		dp[1][i + 1] = min(dp[0][i - 1] + l[i - 1] + l[i], dp[0][i] + l[i])
	print(min(dp[0][n], dp[1][n]))
qwe = 1
qwe = int(input())
for _ in range(qwe):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 1
	j = 0
	out = 0
	if arr[0] == 1:
		out += 1
	while i < n:
		if arr[i] == 1:
			j += 1
		elif j > 0:
			out += j // 3
			j = 0
		i += 1
	if j > 0:
		out += j // 3
	print(out)


rw = int(input())
for qwe in range(rw):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	i = 0
	p = 0
	while i < n - 1:
		if p == 0:
			if i == n - 1:
				p = 1
				break
			if a[i] == 1:
				s += 1
			i += 1
			if i == n - 1:
				p = 1
				break
			if a[i] == 0 and a[i + 1] == 1:
				i += 1
			if i == n - 1:
				p = 1
				break
			p = 1
		elif p == 1:
			i += 1
			if i == n - 1:
				break
			if a[i] == 1:
				i += 1
			if i == n - 1:
				p = 0
				break
			p = 0
	if p == 0:
		if a[n - 1] == 1:
			s += 1
	print(s)


def solve(a, n):
	(friend, us) = ([0] * (n + 1), [0] * (n + 1))
	for i in reversed(range(n)):
		us[i] = friend[i + 1]
		if i + 2 <= n:
			us[i] = min(us[i], friend[i + 2])
		friend[i] = a[i] + us[i + 1]
		if i + 2 <= n:
			friend[i] = min(friend[i], a[i] + a[i + 1] + us[i + 2])
	return friend[0]
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(solve(a, n))


for _ in range(int(input())):
	n = int(input())
	(*difficulty,) = map(int, input().split())
	groups = [0]
	for (i, v) in enumerate(difficulty):
		if v == 0 and (i == 0 or difficulty[i - 1] == 1):
			groups.append(0)
		if v == 1:
			groups[-1] += 1
	ans = (groups[0] + 2) // 3 + sum((v // 3 for v in groups[1:]))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = int(a[0] == 1)
	i = 1
	while i < n - 2:
		if a[i] + a[i + 1] + a[i + 2] == 3:
			ans += 1
			i += 3
		else:
			i += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
		continue
	dp = [[0, 0] for i in range(n)]
	dp[0] = [l[0], 10 ** 9]
	dp[1] = [l[0] + l[1], l[0]]
	for i in range(2, n):
		dp[i][0] = min(dp[i - 1][1] + l[i], l[i - 1] + dp[i - 2][1] + l[i])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	print(min(dp[-1]))


from math import *
from bisect import *
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	a = input()
	a = a.replace(' ', '')
	ans = 0
	a = a.split('0')
	if a[0] != '':
		ans += max(1, ceil(len(a[0]) / 3))
	for i in range(1, len(a)):
		if i == 0:
			ans += max(1, len(a[i]) // 2)
		else:
			ans += len(a[i]) // 3
	print(ans)


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
for _test_ in range(int(input())):
	n = int(input())
	li = get_list()
	ans = li[0]
	g = groupby(li[1:])
	for (ke, va) in g:
		if ke == 1:
			ans += len(list(va)) // 3
	print(ans)


cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	s = a[0]
	i = 1
	while i < n - 2:
		if a[i] + a[i + 1] + a[i + 2] == 3:
			s += 1
			i += 2
		i += 1
	print(s)


from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.read().splitlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx]
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

class Problem:

	def __init__(self):
		N = 200005
		self.oo = float('inf')
		self.dp = [[0, 0] for i in range(N)]
		self.dp[0][0] = self.oo

	def solve(self, n, a):
		for i in range(n):
			k1 = a[i]
			self.dp[i + 1][0] = self.dp[i][1] + k1
			self.dp[i + 1][1] = self.dp[i][0]
			if i > 0:
				k2 = a[i] + a[i - 1]
				self.dp[i + 1][0] = min(self.dp[i + 1][0], self.dp[i - 1][1] + k2)
				self.dp[i + 1][1] = min(self.dp[i + 1][1], self.dp[i - 1][0])
		print(min(*self.dp[n]))
try:
	p = Problem()
	for tc in Input().known_tests():
		p.solve(*tc.array(), tc.array())
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(*a)
		continue
	dp = [[10 ** 7 for i in range(2)] for j in range(n + 1)]
	a = [0] + a
	dp[1][0] = a[1]
	dp[2][0] = a[1] + a[2]
	for i in range(2, n + 1):
		dp[i][1] = min(dp[i][1], dp[i - 1][0], dp[i - 2][0])
		dp[i][0] = min(dp[i][0], dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1])
	print(min(dp[n]))


for _ in range(int(input())):
	n = int(input())
	a = input()
	ans = 0
	if a[0] == '1':
		ans = 1
	ans += a[1:].count('1 1 1')
	print(ans)


import math
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	if n <= 2:
		print(A[0])
	else:
		B = [0 for i in range(n)]
		C = [0 for i in range(n)]
		(B[-1], C[-1]) = (0, A[-1])
		(B[-2], C[-2]) = (0, A[-2])
		for i in range(n - 3, -1, -1):
			B[i] = min(C[i + 1], C[i + 2])
			C[i] = min(A[i] + A[i + 1] + B[i + 2], A[i] + B[i + 1])
		print(C[0])


T = int(input())
ret = []
for t in range(T):
	n = int(input())
	a = [0] + list(map(int, input().split()))
	dpM = [10 ** 7] * (n + 1)
	dpF = [10 ** 7] * (n + 1)
	dpM[0] = 0
	for i in range(1, n + 1):
		dpF[i] = min(dpF[i], dpM[i - 1] + a[i])
		dpF[i] = min(dpF[i], dpM[i - 2] + a[i] + a[i - 1])
		dpM[i] = min(dpM[i], dpF[i - 1])
		dpM[i] = min(dpM[i], dpF[i - 2])
	ret.append(min(dpF[n], dpM[n]))
for t in range(T):
	print(ret[t])


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(p) for p in input().split()]
	i = 0
	cnt = arr[0]
	while i < n - 3:
		m = min(arr[i + 1], arr[i + 2], arr[i + 3])
		if m == 1:
			i += 3
			cnt += 1
		elif m == arr[i + 1]:
			i += 1
		elif m == arr[i + 2]:
			i += 2
		else:
			i += 3
	print(cnt)


import sys
import math
import heapq
from collections import deque
YES = 'YES'
NO = 'NO'
modulo = 10 ** 9 + 7

def solve():
	n = int(input())
	bs = list(map(int, input().split()))
	res = 0 if bs[0] == 0 else 1
	last_zero = 0
	for i in range(1, n):
		if bs[i] == 1:
			continue
		distance = i - last_zero - 1
		res += math.floor(distance / 3)
		last_zero = i
	distance = n - last_zero - 1
	res += math.floor(distance / 3)
	return res
for _ in range(int(input())):
	print(solve())


import math
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	(c, c1) = (0, 0)
	if l[0] == 1:
		c += 1
	for i in range(1, n):
		if l[i] == 1:
			c1 += 1
		else:
			c += c1 // 3
			c1 = 0
	c += c1 // 3
	print(c)


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	q = [0]
	for (i, w) in enumerate(a):
		if w == 0 and (i == 0 or a[i - 1] == 1):
			q.append(0)
		if w == 1:
			q[-1] = q[-1] + 1
	print((q[0] + 2) // 3 + sum((w // 3 for w in q[1:])))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

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

def insr():
	return input().strip()

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

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

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def ceil(a, b):
	return -(-a // b)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


from collections import defaultdict as dd
from sys import stdin, stdout
from bisect import bisect_left
from math import log, sqrt
for t in range(int(stdin.readline().strip())):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().strip().split()))
	c = 0
	b = []
	for i in range(n):
		if a[i]:
			c += 1
		else:
			b.append(c)
			c = 0
	if c:
		b.append(c)
	c = 0
	if a[0] == 1:
		c += 1
		b[0] -= 1
	for i in b:
		c += i // 3
	print(c)


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [999999999] * n
	ans[0] = 1 if arr[0] == 1 else 0
	if n > 1:
		ans[1] = ans[0]
		if n > 2:
			ans[2] = ans[0]
	for i in range(n):
		if i + 1 >= n:
			continue
		if arr[i + 1] == 1:
			ans[i + 1] = min(ans[i + 1], ans[i] + 1)
			if i + 2 < n:
				ans[i + 2] = min(ans[i + 2], ans[i] + 1)
			if i + 3 < n:
				ans[i + 3] = min(ans[i + 3], ans[i] + 1)
		else:
			ans[i + 1] = min(ans[i + 1], ans[i])
			if i + 2 < n:
				ans[i + 2] = min(ans[i + 2], ans[i])
			if i + 3 < n:
				ans[i + 3] = min(ans[i + 3], ans[i])
	print(ans[-1])


def find_ans(n):
	s = list(map(int, input().split()))
	d = [10000] * (n + 1)
	dp = [10000] * (n + 1)
	d[-1] = 0
	dp[-1] = 0
	for i in range(n - 1, -1, -1):
		d[i] = dp[i + 1]
		if i + 2 <= n:
			d[i] = min(d[i], dp[i + 2])
		dp[i] = d[i + 1] + s[i]
		if i + 2 <= n:
			dp[i] = min(dp[i], d[i + 2] + s[i] + s[i + 1])
	print(dp[0])
for _ in range(int(input())):
	n = int(input())
	find_ans(n)


t = int(input())
for index in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	me = [0 for i in range(n + 1)]
	him = [0 for i in range(n + 1)]
	me[n] = 0
	him[n] = 0
	i = n - 1
	while i >= 0:
		me[i] = him[i + 1]
		if i + 2 <= n:
			me[i] = min(him[i + 1], him[i + 2])
		him[i] = me[i + 1] + a[i]
		if i + 2 <= n:
			him[i] = min(me[i + 1] + a[i], me[i + 2] + a[i] + a[i + 1])
		i -= 1
	print(him[0])


t = int(input())
INF = 2000000
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	if n == 1:
		print(int(a[0] == 1))
	else:
		dp = [[INF] * 2 for i in range(n + 3)]
		dp[0][0] = int(a[0] == 1)
		dp[0][1] = 0
		dp[1][0] = int(a[0] == 1) + int(a[1] == 1)
		dp[1][1] = min(dp[1][1], dp[0][0])
		dp[2][1] = min(dp[2][1], dp[0][0])
		for i in range(1, n - 1):
			dp[i + 1][1] = min(dp[i + 1][1], dp[i][0])
			dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + int(a[i + 1] == 1))
			if i + 2 < n:
				dp[i + 2][1] = min(dp[i + 2][1], dp[i][0])
				dp[i + 2][0] = min(dp[i + 2][0], dp[i][1] + int(a[i + 1] == 1) + int(a[i + 2] == 1))
		print(min(dp[n - 1][0], dp[n - 1][1]))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = True
	i = 0
	steps = 0
	while i < n:
		if flag:
			if i + 1 < n:
				if arr[i] == 0:
					if arr[i + 1] == 0 and i + 2 < n and (arr[i + 2] == 1):
						i += 2
					else:
						i += 1
				elif arr[i] == 1:
					if arr[i + 1] == 0 and i + 2 < n and (arr[i + 2] == 1):
						i += 2
					else:
						i += 1
					steps += 1
				flag = False
			else:
				if arr[i] == 0:
					i += 1
				else:
					i += 1
					steps += 1
				flag = False
		elif i + 1 < n:
			if arr[i] == 1 and arr[i + 1] == 1:
				i += 2
			elif arr[i] == 0 and arr[i + 1] == 1:
				i += 2
			else:
				i += 1
			flag = True
		else:
			i += 1
			flag = True
	print(steps)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, 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 SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: 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 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

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
		continue
	l = [0] + l
	dp = [[999999 for i in range(2)] for i in range(n + 1)]
	dp[1][0] = l[1]
	dp[2][0] = l[1] + l[2]
	for i in range(2, n + 1):
		dp[i][1] = min(dp[i][1], dp[i - 1][0], dp[i - 2][0])
		dp[i][0] = min(dp[i][0], dp[i - 1][1] + l[i], dp[i - 2][1] + l[i - 1] + l[i])
	print(min(dp[n]))


tests = int(input())
A = []
for i in range(tests):
	input()
	l = input()
	A = l.split()
	counter = 0
	i = 0
	while i < len(A) and A[i] != '0':
		i += 1
	if i % 3 == 0:
		counter += int(i / 3)
	else:
		counter += int(i / 3) + 1
	start = -1
	for j in range(i, len(A)):
		if A[j] != '0':
			if start == -1:
				start = j
		elif start != -1:
			length = j - start
			if length % 3 == 0:
				counter += int(length / 3)
			else:
				counter += int(length / 3)
			start = -1
	if start != -1:
		length = j - start + 1
		if length % 3 == 0:
			counter += int(length / 3)
		else:
			counter += int(length / 3)
	print(counter)


import io
import os
import sys
import math
fileno = sys.stdin.fileno()
input = io.BytesIO(os.read(fileno, os.fstat(fileno).st_size)).readline
T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	F = [None for i in range(N)]
	M = [None for i in range(N)]
	F[0] = A[0]
	M[0] = 1000000000
	if N != 1:
		F[1] = A[0] + A[1]
		M[1] = A[0]
	for i in range(2, N):
		F[i] = min(M[i - 1] + A[i], M[i - 2] + A[i - 1] + A[i])
		M[i] = min(F[i - 1], F[i - 2])
	print(min(F[N - 1], M[N - 1]))


def sol(n, a):
	idx = 0
	pts = 0
	while idx < n:
		pts += a[idx]
		if (idx + 4 >= n or a[idx + 4] == 0) and (idx + 1 >= n or a[idx + 1] == 0):
			idx += 4
		elif idx + 3 >= n or a[idx + 3] == 0:
			idx += 3
		elif idx + 2 >= n or a[idx + 2] == 0:
			idx += 2
		elif idx + 1 >= n or a[idx + 1] == 0:
			idx += 1
		else:
			idx += 3
	return pts

def main():
	T = int(input())
	for t in range(T):
		n = int(input())
		a = list(map(int, input().split()))
		print(sol(n, a))
main()


t = int(input())
a = []
for i in range(t):
	x = int(input())
	x1 = list(map(int, input().split()))
	a.append(x1)
ans = []
for i in range(t):
	x = len(a[i])
	DPX = [float('inf')] * (x + 1)
	DPY = [float('inf')] * (x + 1)
	DPX[0] = 0
	for j in range(1, x + 1):
		for k in range(1, 3):
			if k == 1:
				DPY[j] = min(DPX[j - k] + a[i][j - 1], DPY[j])
				DPX[j] = min(DPY[j - k], DPX[j])
			if k == 2 and j != 1:
				DPY[j] = min(DPX[j - k] + a[i][j - 1] + a[i][j - 2], DPY[j])
				DPX[j] = min(DPY[j - k], DPX[j])
	ans.append(min(DPX[-1], DPY[-1]))
for i in ans:
	print(i)


def solve(arr, n):
	if n == 1 or n == 2:
		return arr[0]
	mn = {n: 0}
	mx = {n: 0}
	tot = {n: 0}
	for i in range(n - 1, n - 3, -1):
		if i >= 0:
			mn[i] = arr[i]
			mx[i] = mx[i + 1] + arr[i]
			tot[i] = tot[i + 1] + arr[i]
	for i in range(n - 3, -1, -1):
		mn[i] = float('inf')
		mx[i] = float('-inf')
		done = 0
		for j in range(2):
			done += arr[i + j]
			mn[i] = min(mn[i], tot[i + 1 + j] - mx[i + 1 + j] + done)
			mx[i] = max(mx[i], tot[i + j + 1] - mn[i + j + 1] + done)
		tot[i] = tot[i + 1] + arr[i]
	return mn[0]
for case in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = solve(arr, n)
	print(ans)


def decider(arr, N):
	output = 0
	i = 0
	if N > 3:
		while i <= N - 4:
			if arr[i + 1:i + 3] == [0, 0]:
				if arr[i] == 1:
					output += 1
				i += 2
			else:
				if arr[i] == 1:
					output += 1
				i += 1
				if arr[i] == 1:
					i += 1
					if arr[i] == 1:
						i += 1
				else:
					i += 2
					if arr[i] == 1:
						i += 1
	if i < N:
		if arr[i] == 1:
			output += 1
	return output
for i in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	print(decider(arr, N))


for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	k = s[1:].count('1 1 1')
	print(k + int(s[0]))


from sys import stdin, stdout, setrecursionlimit
from collections import defaultdict as dd
from math import ceil
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [10 ** 9] * n
	b[0] = a[0]
	c = b[:]
	d = b[:]
	e = b[:]
	c[0] = d[0] = e[0] = 10 ** 9
	for i in range(1, n):
		b[i] = min(d[i - 1], e[i - 1]) + a[i]
		c[i] = b[i - 1] + a[i]
		d[i] = min(c[i - 1], b[i - 1])
		e[i] = d[i - 1]
	print(min(b[-1], c[-1], d[-1], e[-1]))


t = int(input())
for t_ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if len(a) <= 3:
		print(a[0])
	else:
		(x, y, z, w) = (10, 10, a[0], a[0] + a[1])
		for i in range(2, n):
			(x, y, z, w) = (z, min(x, z) + a[i], min(y, w), y + a[i])
		print(min(x, y, z, w))


for i in range(int(input())):
	n = int(input())
	tower = [int(j) for j in input().split()]
	j = 0
	friend1s_turn = True
	points = 0
	while j < n:
		if friend1s_turn:
			if tower[j] == 1:
				points += 1
			if n - j > 2:
				if tower[j + 1] == 1 or tower[j + 2] == 0:
					j += 1
					friend1s_turn = False
				else:
					j += 2
					friend1s_turn = False
			elif n - j > 1:
				if tower[j + 1] == 1:
					j += 1
					friend1s_turn = False
				else:
					j += 2
					friend1s_turn = False
			else:
				j += 1
		elif n - j > 1:
			if tower[j + 1] == 1:
				j += 2
				friend1s_turn = True
			else:
				j += 1
				friend1s_turn = True
		else:
			j += 1
			friend1s_turn = True
	print(points)


from math import ceil
for _ in range(int(input())):
	N = int(input())
	List = [int(x) for x in input().split()]
	concur = []
	add = 0
	for i in range(N):
		if List[i] == 1:
			add += 1
		elif add:
			concur.append(add)
			add = 0
	if add:
		concur.append(add)
	skip = 0
	if List[0] == 1:
		flag = True
	else:
		flag = False
	if concur:
		for i in range(len(concur)):
			if flag and i == 0:
				skip += ceil(concur[i] / 3)
			else:
				skip += int(concur[i] // 3)
		print(skip)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	friend = True
	flag = True
	pts = 0
	while flag:
		if friend:
			if a[i] == 1:
				pts += 1
				i += 1
			if i < n:
				while a[i] == 0:
					i += 1
					if i == n:
						flag = False
						break
			friend = False
		else:
			i += 1
			if i < n:
				if a[i] == 1:
					i += 1
			friend = True
		if i >= n:
			flag = False
	print(pts)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	us = [0] * (n + 1)
	him = [0] * (n + 1)
	for i in reversed(range(n)):
		him[i] = us[i + 1] + a[i]
		if i + 2 <= n:
			him[i] = min(him[i], us[i + 2] + a[i] + a[i + 1])
		us[i] = him[i + 1]
		if i + 2 <= n:
			us[i] = min(us[i], him[i + 2])
	print(him[0])


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(0)
	c = a[0]
	b = 0
	for i in range(1, n + 1):
		if a[i] == 0:
			c += b // 3
			b = 0
		else:
			b += 1
	print(c)


for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	Data = [[0, 0, 0, 0] for i in range(n + 1)]
	Data[0] = [100000000, 100000000, 100000000, 0]
	for i in range(1, n + 1):
		Data[i][0] = Data[i - 1][1] + A[i - 1]
		Data[i][1] = min(Data[i - 1][2], Data[i - 1][3]) + A[i - 1]
		Data[i][2] = min(Data[i - 1][0], Data[i - 1][1])
		Data[i][3] = Data[i - 1][2]
	print(min(Data[n]))


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	i = 1
	ans = l1[0]
	friend = 1
	me = 0
	temp = 0
	while i < n:
		if l1[i]:
			temp += 1
			if temp == 3:
				ans += 1
				temp = 0
		else:
			temp = 0
		i += 1
	print(ans)


for _ in range(int(input())):
	N = int(input())
	X = list(map(str, input().split()))
	c = 0
	if X[0] == '1':
		c += 1
	s = ''.join(X[1:])
	print(c + s.count('111'))


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def I():
	return int(sys.stdin.readline())

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
from functools import lru_cache
for _ in range(I()):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(0)
	c = a[0]
	b = 0
	for i in range(1, n + 1):
		if a[i] == 0:
			c += b // 3
			b = 0
		else:
			b += 1
	print(c)


mod = 10 ** 9 + 7

def solve():
	n = int(input())
	global a
	a = list(map(int, input().split()))
	a.append(0)
	a.append(0)
	a.append(0)
	dp = [0 for i in range(n + 10)]
	for i in range(n - 1, -1, -1):
		dp[i] = a[i] + min(dp[i + 2], dp[i + 3], a[i + 1] + min(dp[i + 3], dp[i + 4]))
	print(dp[0])
t = int(input())
while t > 0:
	solve()
	t -= 1


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
inf = 10 ** 16
for _ in range(II()):
	n = II()
	aa = LI()

	def chmin(i, j, val):
		if j > n:
			return
		if val < dp[i][j]:
			dp[i][j] = val
	dp = [[inf] * (n + 1) for _ in range(2)]
	dp[0][0] = 0
	for j in range(n):
		for i in range(2):
			pre = dp[i][j]
			if pre == inf:
				continue
			if i == 0:
				chmin(1, j + 1, pre + aa[j])
				if j + 1 < n:
					chmin(1, j + 2, pre + aa[j] + aa[j + 1])
			else:
				chmin(0, j + 1, pre)
				chmin(0, j + 2, pre)
	ans = min(dp[0][n], dp[1][n])
	print(ans)


for t in range(int(input())):
	len = int(input())
	array = [int(x) for x in input().split()]
	p = 1
	k = 0
	k += array[0] == 1
	while p < len:
		if not array[p]:
			p += 1
			continue
		j = p
		while j < len and array[j]:
			j += 1
		k += (j - p) // 3
		p = j
	print(k)


from random import shuffle

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		ans = a[0]
		ones = 0
		for e in a[1:]:
			if e:
				ones += 1
			else:
				ans += ones // 3
				ones = 0
		ans += ones // 3
		print(ans)
solve()


n = int(input())
for _ in range(n):
	k = int(input())
	boss = list(map(int, input().split()))
	if k == 1:
		print(boss[0])
	else:
		dp = [[float('inf') for _ in range(2)] for l in range(k)]
		dp[0][0] = boss[0]
		dp[1][0] = boss[0] + boss[1]
		dp[0][1] = float('inf')
		dp[1][1] = boss[0]
		for i in range(2, k):
			dp[i][0] = min(dp[i - 1][1] + boss[i], dp[i - 2][1] + boss[i - 1] + boss[i])
			dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
		print(min(dp[k - 1][0], dp[k - 1][1]))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 1
	j = 0
	out = 0
	if arr[0] == 1:
		out += 1
	while i < n:
		if arr[i] == 1:
			j += 1
		elif j > 0:
			out += j // 3
			j = 0
		i += 1
	if j > 0:
		out += j // 3
	print(out)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	ans = int(a[0] == 1)
	x = 0
	for i in range(1, n):
		if a[i] == 1:
			x += 1
		else:
			ans += x // 3
			x = 0
	ans += x // 3
	print(ans)


import math

def solve():
	n = int(input())
	arr = [int(i) for i in input().split()]
	(count, i) = (0, 0)
	ch = True
	while i < n:
		if ch:
			ch = False
			if i < n - 1 and arr[i] == 0 and (arr[i + 1] == 0):
				i += 2
				continue
			if arr[i] == 0:
				i += 1
				continue
			if i < n - 1:
				if arr[i] == 1 and arr[i + 1] == 0:
					count += 1
					i += 2
					continue
				if arr[i] == 1 and arr[i + 1] == 1:
					i += 1
					count += 1
					continue
			elif arr[i] == 1:
				count += 1
				i += 1
		else:
			ch = True
			if i < n - 1:
				if arr[i] == 1 and arr[i + 1] == 1:
					i += 2
					continue
				if arr[i] == 1 and arr[i + 1] == 0:
					i += 1
			else:
				i += 1
	return count
for i in range(int(input())):
	print(solve())


h = int(input())
l = []
for i in range(h):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] == 0:
		sum = 0
	else:
		sum = 1
	bool = False
	for i in range(1, n):
		if bool:
			if i < j - 1:
				continue
		if a[i] == 0:
			continue
		j = i
		while j < n and a[j] == 1:
			j += 1
		sum += (j - i) // 3
		i = j - 1
		bool = True
	print(sum)


for i in range(int(input())):
	n = int(input())
	a = '1 1 ' + input()
	print(a.count('1 1 1'))


def main():
	n = int(input())
	arr = input().split(' ')
	cost = 1 if arr[0] == '1' else 0
	(segment, i) = (0, 1)
	while i < n:
		if arr[i] == 0:
			i += 1
		else:
			j = i
			while j < n and arr[j] == '1':
				j += 1
			cost += (j - i) // 3
			i = j + 1
	print(cost)
for _ in range(int(input())):
	main()


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	dp = [[sys.maxsize, sys.maxsize] for _ in range(n + 2)]
	dp[0][1] = 0
	for i in range(1, n + 1):
		if i > 1:
			dp[i][0] = min(dp[i - 1][1] + arr[i - 1], dp[i - 2][1] + arr[i - 2] + arr[i - 1])
			dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
		else:
			dp[i][0] = dp[i - 1][1] + arr[i - 1]
			dp[i][1] = dp[i - 1][0]
	print(min(dp[n][0], dp[n][1]))


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	pos = 0
	skip = 0
	zeros = 0
	left = 0
	points = 0
	while pos < n:
		if lst[pos] == 0:
			zeros = True
		else:
			if zeros:
				left = 2
				zeros = False
			if left:
				left -= 1
			else:
				points += 1
				left = 2
		pos += 1
	print(points)
t = int(input())
for i in range(t):
	main()


import os
import sys
from io import BytesIO, IOBase

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		a = lin()
		if n == 1:
			print(a[0])
		else:
			dp = [[0, 0] for i in range(n)]
			dp[-1][1] = a[-1]
			dp[-2][1] = a[-2]
			for i in range(n - 3, -1, -1):
				dp[i][0] = min(dp[i + 1][1], dp[i + 2][1])
				dp[i][1] = a[i] + min(dp[i + 1][0], a[i + 1] + dp[i + 2][0])
			print(dp[0][1])
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')

def iin():
	return int(input())

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


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	dp = [[10000000000 for i in range(n)] for j in range(2)]
	for j in range(n):
		if j == 0:
			dp[0][j] = arr[j]
		elif j == 1:
			dp[0][j] = arr[j - 1] + arr[j]
			dp[1][j] = dp[0][j - 1]
		elif j == 2:
			dp[0][j] = dp[1][j - 1] + arr[j]
			dp[1][j] = dp[0][0]
		else:
			dp[0][j] = min(dp[1][j - 1] + arr[j], dp[1][j - 2] + arr[j] + arr[j - 1])
			dp[1][j] = min(dp[0][j - 1], dp[0][j - 2])
	print(min(dp[0][-1], dp[1][-1]))


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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')

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

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

def N():
	return int(input())
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	res = []
	for (ch, g) in groupby(it):
		res.append((ch, len(list(g))))
	return res

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = N()
for i in range(t):
	n = N()
	a = RLL()
	if n == 1:
		print(a[0])
		continue
	dp = [[inf] * 2 for i in range(n)]
	dp[0][0] = a[0]
	dp[1][0] = a[0] + a[1]
	dp[1][1] = a[0]
	for i in range(2, n):
		dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	print(min(dp[n - 1]))


t = eval(input())
for _ in range(t):
	input()
	nums = list(map(int, input().strip().split(' ')))
	prev = nums[0]
	prefix = []
	prefix.append(prev)
	prev = 0
	for i in range(1, len(nums)):
		num = nums[i]
		if num == 0 and prev != 0:
			prefix.append(prev)
			prev = 0
		prev += num
	prefix.append(prev)
	min_ = 0
	for (i, num) in enumerate(prefix):
		if i == 0:
			min_ += max(num // 2, 1) if num else 0
		else:
			min_ += num // 3
	print(min_)


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

def main():
	pass
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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

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

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
for xyz in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
	else:
		me = [-1] * n
		him = [-1] * n
		me[0] = 10000000000000000
		him[0] = l[0]
		me[1] = him[0]
		him[1] = him[0] + l[1]
		for i in range(2, n):
			him[i] = min(me[i - 1] + l[i], me[i - 2] + l[i] + l[i - 1])
			me[i] = min(him[i - 1], him[i - 2])
		print(min(him[-1], me[-1]))


def fn(a, n):
	if a[0] == 1:
		count = 1
	else:
		count = 0
	t = 0
	tc = 1
	for i in range(1, n):
		if a[i] == 1:
			if t == 1:
				if tc == 0:
					tc = 1
				elif tc == 1:
					tc = 0
					t = 0
			elif tc == 0:
				tc = 1
				count += 1
			else:
				t = 1
				tc = 1
		elif t == 1:
			if tc == 0:
				tc = 1
			elif tc == 1:
				t = 0
				tc = 1
		elif tc == 0:
			tc = 1
		elif tc == 1:
			k = hel(a, i, n)
			if k == 0:
				t = 1
				tc = 0
			else:
				t = 1
				tc = 1
	return count

def hel(a, i, n):
	if i + 1 < n:
		if a[i + 1] == 1:
			return 0
		elif a[i + 1] == 0:
			if i + 2 < n:
				if a[i + 2] == 1:
					return 1
				else:
					return 0
			return 0
	return 0
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(fn(a, n))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	st = 0
	kill = 0
	ans = 0
	i = 0
	while i < n:
		if st == 0:
			if arr[i] == 0:
				i += 1
				kill += 1
			elif kill != 0:
				st = 1
				kill = 0
			else:
				i += 1
				ans += 1
				kill += 1
			if kill == 2:
				st = 1
				kill = 0
		else:
			if arr[i] == 1:
				kill += 1
				i += 1
			else:
				st = 0
				kill = 0
			if kill == 2:
				st = 0
				kill = 0
	print(ans)


def solve(arr, n, ans):
	dp = [[[float('inf') for k in range(3)] for j in range(2)] for i in range(n)]
	if arr[0] != 0:
		dp[0][1][1] = 1
	else:
		dp[0][1][1] = 0
	for i in range(1, n):
		for player in range(2):
			for prev_chances in range(3):
				if prev_chances + 1 <= 2:
					if player == 0:
						dp[i][player][prev_chances + 1] = dp[i - 1][player][prev_chances]
					elif arr[i] == 0:
						dp[i][player][prev_chances + 1] = dp[i - 1][player][prev_chances]
					else:
						dp[i][player][prev_chances + 1] = dp[i - 1][player][prev_chances] + 1
		dp[i][0][1] = min(dp[i][0][1], dp[i - 1][1][1], dp[i - 1][1][2])
		if arr[i] == 0:
			add = 0
		else:
			add = 1
		dp[i][1][1] = min(dp[i][1][1], dp[i - 1][0][1] + add, dp[i - 1][0][2] + add)
	min_val = float('inf')
	for i in range(2):
		min_val = min(min_val, min(dp[-1][i]))
	ans.append(str(min_val))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	print('\n'.join(ans))
main()


for _ in range(int(input())):
	i_boss = int(input())
	bossy = input()
	print(('1 1 ' + bossy).count('1 1 1'))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	seq = 0
	ans = a[0]
	for i in range(1, n):
		if a[i] == 1:
			seq += 1
		else:
			ans += seq // 3
			seq = 0
	ans += seq // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	p = 0
	if a[0] == 1:
		c = c + 1
	for j in range(1, n):
		if a[j] == 1:
			p = p + 1
		else:
			c = c + p // 3
			p = 0
	c = c + p // 3
	print(c)


def result():
	global n, i
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	if arr[0] == 1:
		count += 1
	i = 1
	while i < n - 1:
		if arr[i] == 0:
			i += 1
			continue
		j = i
		while j < n and arr[j] == 1:
			j += 1
		count += (j - i) // 3
		i = j
	print(count)
t = int(input())
while t > 0:
	result()
	t = t - 1


from sys import maxsize, stdout, stdin
fullans = ''
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	ls = list(map(int, stdin.readline().split()))
	dp = [[maxsize, maxsize] for i in range(n + 1)]
	dp[n] = [0, 0]
	dp[n - 1][0] = 0
	dp[n - 1][1] = ls[n - 1]
	for i in range(n - 2, -1, -1):
		mn = maxsize
		dp[i][0] = min(dp[i + 1][1], dp[i + 2][1])
		dp[i][1] = min(dp[i + 1][0], dp[i + 2][0] + ls[i + 1]) + ls[i]
	fullans += str(dp[0][1]) + '\n'
stdout.write(fullans)


from bisect import bisect_left, bisect_right
from sys import stdin, stdout, maxsize
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
for tc in range(int(R())):
	n = int(R())
	a = RL(int)
	dp = [[a[0], a[0]], [a[0], a[0]]]
	for i in range(1, n):
		me = min(dp[-1][1], dp[-2][1])
		fr = min(dp[-1][0], dp[-2][0] + a[i - 1]) + a[i]
		dp.append([me, fr])
	print(min(dp[-1]))


import math
t = int(input())
for i in range(t):
	n = int(input())
	a_s = list(map(int, input().split()))
	s = a_s[0]
	del a_s[0]
	one_nums = [0]
	for i in a_s:
		if i == 1:
			one_nums[-1] += 1
		elif one_nums[-1] != 0:
			one_nums.append(0)
	s += sum(list(map(lambda t: t // 3, one_nums)))
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(0)
	a.append(0)
	him = [0] * (n + 2)
	us = [0] * (n + 2)
	for i in range(n - 1, -1, -1):
		us[i] = min(him[i + 1], him[i + 2])
		him[i] = min(a[i] + us[i + 1], a[i] + a[i + 1] + us[i + 2])
	print(him[0])


t = int(input())
for i in range(t):
	n = int(input())
	tower = list(map(int, input().split(' ')))
	dp = []
	if tower[0] == 1:
		dp.append([n + 1, n + 1, 1, n + 1])
	else:
		dp.append([n + 1, n + 1, 0, n + 1])
	for j in range(1, n):
		step = []
		step.append(dp[j - 1][2] + tower[j])
		step.append(min(dp[j - 1][0], dp[j - 1][2]))
		step.append(min(dp[j - 1][1] + tower[j], dp[j - 1][3] + tower[j]))
		step.append(dp[j - 1][1])
		dp.append(step)
	print(min(dp[n - 1]))


for s in [*open(0)][2::2]:
	print(('1 1 ' + s).count('1 1 1'))


import sys
input = sys.stdin.buffer.readline
INF = 10 ** 18
Q = int(input())
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	dp = [[INF] * 4 for _ in range(N + 1)]
	dp[0][3] = 0
	for (i, a) in enumerate(A):
		dp[i + 1][0] = min(dp[i + 1][0], min(dp[i][2], dp[i][3]) + a)
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + a)
		dp[i + 1][2] = min(dp[i + 1][2], min(dp[i][0], dp[i][1]))
		dp[i + 1][3] = min(dp[i + 1][3], dp[i][2])
	print(min(dp[-1]))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	f = y = 0
	i = 1
	if a[0] == 1:
		f += 1
	while i < n:
		if a[i] == 1:
			if y == 0:
				y += 1
			elif y == 1:
				y += 1
			else:
				f += 1
				y = 0
		else:
			y = 0
		i += 1
	print(f)


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		you = [0] * (n + 1)
		me = [0] * (n + 1)
		for i in range(n - 1, -1, -1):
			me[i] = ar[i] + you[i + 1]
			if i + 2 <= n:
				me[i] = min(me[i], ar[i] + ar[i + 1] + you[i + 2])
			you[i] = me[i + 1]
			if i + 2 <= n:
				you[i] = min(you[i], me[i + 2])
		print(me[0])
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')
main()


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(mints())
	dp = [[int(1000000000.0)] * (n + 1), [int(1000000000.0)] * (n + 1)]
	dp[0][0] = 0
	dp[0][1] = dp[1][0]
	dp[1][1] = dp[0][0] + a[0]
	for i in range(1, n):
		dp[0][i + 1] = min(dp[1][i - 1], dp[1][i])
		dp[1][i + 1] = min(dp[0][i - 1] + a[i] + a[i - 1], dp[0][i] + a[i])
	print(min(dp[0][n], dp[1][n]))
for i in range(mint()):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	if arr[0] == 1:
		count += 1
	i = 2
	while i < len(arr) - 1:
		if arr[i - 1] == 1 and arr[i] == 1 and (arr[i + 1] == 1):
			count += 1
			i += 3
		else:
			i += 1
	print(count)


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mi())
	friend = 0
	i = 1
	skip = 0
	if a[0] == 1:
		skip = 1
	(zc, oc) = (0, 0)
	a = a[1:]
	n -= 1
	if 1 not in a:
		print(skip)
		continue
	i = a.index(1)
	while i < n:
		while i < n and a[i] == 1:
			i += 1
			oc += 1
		while i < n and a[i] == 0:
			i += 1
			zc += 1
		skip += oc // 3
		oc = 0
	print(skip)


for t in range(int(input())):
	input()
	b = input()
	print(('1 1 ' + b).count('1 1 1'))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

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

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 zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = 10 ** 9

@iterative
def rec(pos, kon, a, dp):
	if pos >= len(a):
		yield 0
	if dp[pos][kon] != inf:
		yield dp[pos][kon]
	temp = inf
	ll = len(a)
	if kon == 1:
		temp = min(temp, (yield rec(pos + 1, 1 - kon, a, dp)))
		temp = min(temp, (yield rec(pos + 2, 1 - kon, a, dp)))
	elif a[pos] == 0:
		temp = min(temp, (yield rec(pos + 1, 1 - kon, a, dp)))
		if pos + 1 < ll:
			if a[pos + 1] == 1:
				temp = min(temp, 1 + (yield rec(pos + 2, 1 - kon, a, dp)))
			else:
				temp = min(temp, (yield rec(pos + 2, 1 - kon, a, dp)))
	else:
		temp = min(temp, 1 + (yield rec(pos + 1, 1 - kon, a, dp)))
		if pos + 1 < ll:
			if a[pos + 1] == 0:
				temp = min(temp, 1 + (yield rec(pos + 2, 1 - kon, a, dp)))
			else:
				temp = min(temp, 2 + (yield rec(pos + 2, 1 - kon, a, dp)))
	dp[pos][kon] = temp
	yield temp

def solve(case):
	dp = []
	n = int(inp())
	for i in range(n):
		temp = []
		for j in range(2):
			temp.append(inf)
		dp.append(temp)
	a = lis()
	if n == 1:
		print(a[0])
		return
	print(rec(0, 0, a, dp))
testcase(int(inp()))


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split())) + [0]
	INF = 10 ** 9
	dp = [[INF, INF] for _ in range(n + 2)]
	dp[0][1] = 0
	for i in range(n):
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][0])
		dp[i + 2][1] = min(dp[i + 2][1], dp[i][0])
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + a[i])
		dp[i + 2][0] = min(dp[i + 2][0], dp[i][1] + a[i] + a[i + 1])
	print(min(dp[n]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	F = [0] * (n + 1)
	Y = [0] * (n + 1)
	F[n - 1] = a[n - 1]
	Y[n - 1] = 0
	for i in range(n - 2, -1, -1):
		F[i] = min(Y[i + 1] + a[i], Y[i + 2] + a[i] + a[i + 1])
		Y[i] = min(F[i + 1], F[i + 2])
	print(F[0])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = 0
	if ar[0] == 1:
		ans += 1
	li = []
	count = 0
	if n > 1:
		for i in range(1, n):
			if ar[i] == 0:
				if count != 0:
					li.append(count)
					count = 0
			else:
				count += 1
		if count != 0:
			li.append(count)
	for i in li:
		ans += i // 3
	print(ans)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		ans = 0
		count = 0
		for x in range(1, n):
			if l[x] == 1:
				count += 1
			else:
				if count != 0:
					ans += count // 3
				count = 0
		if count:
			ans += count // 3
		if l[0] == 1:
			ans += 1
			print(ans)
		else:
			print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	dp = [[0 for i in range(2)] for i in range(n)]
	dp[-1][1] = li[-1]
	for i in range(n - 2, -1, -1):
		if i + 2 < n:
			dp[i][0] = min(dp[i + 2][1], dp[i + 1][1])
		dp[i][1] = dp[i + 1][0] + li[i]
		if i + 2 < n:
			dp[i][1] = min(dp[i][1], dp[i + 2][0] + li[i] + li[i + 1])
	print(dp[0][1])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from math import inf

def main():
	points = 0
	turnsInARow = 1

	def solve():
		n = int(input())
		bosses = [int(x) for x in input().split()]
		dp = [[[0, 0] for player in range(2)] for boss in range(n)]
		dp[0][0][points] = inf
		dp[0][1][points] = bosses[0]
		dp[0][1][turnsInARow] = 1
		for i in range(1, n):
			for player in range(2):
				option1 = dp[i - 1][player][points] + player * bosses[i] if dp[i - 1][player][turnsInARow] < 2 else inf
				option2 = dp[i - 1][1 - player][points] + player * bosses[i]
				dp[i][player][points] = min(option1, option2)
				dp[i][player][turnsInARow] = 1
				if option1 < option2:
					dp[i][player][turnsInARow] += 1
		print(min(dp[-1][0][points], dp[-1][1][points]))
	t = int(input())
	for i in range(t):
		solve()
BUFFSIZE = 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, BUFFSIZE))
			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, BUFFSIZE))
			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')
input = lambda : sys.stdin.readline().rstrip('\r\n')

def print(*args, **kwargs):
	sep = kwargs.pop('sep', ' ')
	file = kwargs.pop('file', sys.stdout)
	atStart = True
	for x in args:
		if not atStart:
			file.write(sep)
		file.write(str(x))
		atStart = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
main()


from itertools import groupby
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = 0
	if arr[0] == 1:
		ans += 1
	for (a, b) in groupby(arr[1:]):
		if a == 1:
			ans += len(list(b)) // 3
	print(ans)


from sys import stdin, stdout

def find(arr, N):
	dp = [[0] * (N + 1), [0] * (N + 1)]
	for i in range(N)[::-1]:
		for j in range(2):
			dp[j][i] = (arr[i] if j == 0 else 0) + dp[1 - j][i + 1]
			if i < N - 1:
				dp[j][i] = min(dp[j][i], (arr[i] + arr[i + 1] if j == 0 else 0) + dp[1 - j][i + 2])
	return dp[0][0]

def main():
	for _ in range(int(stdin.readline())):
		N = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		print(find(arr, N))
main()


from sys import stdin, stdout
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007

def solve():
	n = inp()
	l = li()
	ans = 0
	ans += l[0] == 1
	i = 1
	while i < n:
		if l[i] == 0:
			i += 1
			continue
		j = i
		while j < n and l[j] == 1:
			j += 1
		ans += (j - i) // 3
		i = j
	pr(ans)
for _ in range(inp()):
	solve()


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(str, input().split()))
	c = 0
	if a[0] == '1':
		c = c + 1
	s = ''.join(a[1:])
	print(c + s.count('111'))


for _ in range(int(input())):
	n = int(input())
	types = list(map(int, input().split()))
	if n == 1:
		print(types[0])
		continue
	dp = [[float('inf'), float('inf')] for _ in range(n)]
	if types[0] == 1:
		dp[0][0] = 1
	else:
		dp[0][0] = 0
	if types[1] == 1:
		dp[1][0] = 1 + dp[0][0]
		dp[1][1] = dp[0][0]
	else:
		dp[1][0] = dp[0][0]
		dp[1][1] = dp[0][0]
	for i in range(2, n):
		dp[i][1] = dp[i - 2][0]
		dp[i][1] = min(dp[i][1], dp[i - 1][0])
		dp[i][0] = dp[i - 1][1] + types[i]
		dp[i][0] = min(dp[i][0], dp[i - 2][1] + types[i - 1] + types[i])
	print(min(dp[-1]))


import sys, os, math
t = int(sys.stdin.readline())
for i in range(0, t):
	n = str(sys.stdin.readline())
	arr = [int(x) for x in sys.stdin.readline().split()]
	C_A = []
	if len(arr) <= 3:
		print(arr[0])
	elif len(arr) == 4:
		print(arr[0] + min(arr[1:]))
	else:
		C_A.append(arr[-1])
		C_A.append(arr[-2])
		C_A.append(arr[-3])
		C_A.append(arr[-4] + min(arr[-1], arr[-2], arr[-3]))
		for i in range(4, len(arr)):
			a = arr[-(i + 1)] + C_A[i - 2]
			b = arr[-(i + 1)] + C_A[i - 3]
			c = arr[-(i + 1)] + arr[-i] + C_A[i - 3]
			d = arr[-(i + 1)] + arr[-i] + C_A[i - 4]
			C_A.append(min(a, b, c, d))
		ans = C_A[-1]
		print(ans)


gans = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		gans.append(str(a[0]))
		continue
	d0 = [0] * n
	d1 = [0] * n
	d0[0] = 100000000000
	d1[0] = a[0]
	d0[1] = a[0]
	d1[1] = a[0] + a[1]
	for i in range(2, n):
		d0[i] = min(d1[i - 1], d1[i - 2])
		d1[i] = min(d0[i - 1] + a[i], d0[i - 2] + a[i] + a[i - 1])
	gans.append(str(min(d0[n - 1], d1[n - 1])))
print('\n'.join(gans))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	DP = [[float('inf')] * 2 for j in range(n + 1)]
	DP[0][0] = 0
	for j in range(1, n + 1):
		d0 = DP[j][0]
		if j >= 2:
			d0 = min(d0, DP[j - 2][1])
		if j >= 1:
			d0 = min(d0, DP[j - 1][1])
		DP[j][0] = d0
		d1 = DP[j][1]
		if j >= 2:
			d1 = min(d1, DP[j - 2][0] + sum(A[j - 2:j]))
		if j >= 1:
			d1 = min(d1, DP[j - 1][0] + A[j - 1])
		DP[j][1] = d1
	print(min(DP[-1][0], DP[-1][1]))


def process():
	n = int(input())
	a = list(map(int, input().split()))
	i = 1
	points = 0
	while i < n:
		while i < n:
			if a[i] == 1:
				break
			i += 1
		count_1 = 0
		while i < n:
			if a[i] == 0:
				break
			count_1 += 1
			i += 1
		points += count_1 // 3
	if a[0] == 1:
		points += 1
	print(points)

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


for _ in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	if a[0] == 1:
		res = 1
		i = 1
	else:
		res = 0
		i = 0
	while i < n:
		j = i + 1
		while j < n and a[j] == a[i]:
			j += 1
		if a[i] == 1:
			res += (j - i) // 3
		i = j
	print(res)


ansl = []
for _ in range(int(input())):
	n = int(input())
	al = list(map(int, input().split()))
	al.append(0)
	INF = 10 ** 5
	dp_me = [INF] * (n + 5)
	dp = [INF] * (n + 5)
	dp[0] = 0
	for i in range(n):
		dp[i + 2] = min(dp[i] + al[i], dp[i + 2])
		dp[i + 3] = min(dp[i] + al[i], dp[i + 3])
		dp[i + 3] = min(dp[i] + al[i] + al[i + 1], dp[i + 3])
		dp[i + 4] = min(dp[i] + al[i] + al[i + 1], dp[i + 4])
	ans = min(dp[n:n + 5])
	ansl.append(ans)
for ans in ansl:
	print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def solve(arr, n):
	res = 0
	if arr[0] == 1:
		res += 1
	i = 1
	while i < n - 2:
		if arr[i] + arr[i + 1] + arr[i + 2] == 3:
			res += 1
			i += 3
		else:
			i += 1
	return res
t = inp()
while t > 0:
	n = inp()
	arr = inlt()
	print(solve(arr, n))
	t -= 1


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	pos = 0
	left = 0
	points = 0
	while pos < n:
		if lst[pos] == 0:
			left = 2
		elif left:
			left -= 1
		else:
			points += 1
			left = 2
		pos += 1
	print(points)
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = a[0]
	if n == 1:
		print(ans)
		continue
	b = []
	c = 1
	for i in range(2, n):
		if a[i] == a[i - 1]:
			c += 1
		else:
			b.append(c)
			c = 1
	b.append(c)
	if a[1] == 0:
		zero = True
	else:
		zero = False
	for i in range(len(b)):
		if zero == False:
			ans += b[i] // 3
			zero = True
		else:
			zero = False
	print(ans)


def solve(arr, n):
	ans = 1 if arr[0] == 1 else 0
	i = 1
	j = 0
	while i < n:
		if arr[i] == 0:
			i += 1
			continue
		j = i
		while j < n and arr[j] == 1:
			j += 1
		ans += (j - i) // 3
		i = j - 1
		i += 1
	print(ans)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		solve(list(map(int, input().split())), n)
main()


from sys import stdin
t = int(stdin.readline())
for loop in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	dp = [[float('inf'), float('inf')] for i in range(n)]
	for i in range(n):
		if i == 0:
			dp[i][0] = a[0]
			continue
		elif i == 1:
			dp[i][0] = a[0] + a[1]
			dp[i][1] = dp[i - 1][0]
			continue
		dp[i][0] = min(dp[i - 2][1] + a[i - 1] + a[i], dp[i - 1][1] + a[i])
		dp[i][1] = min(dp[i - 2][0], dp[i - 1][0])
	print(min(dp[-1]))


T = int(input())
for _ in range(T):
	n = int(input())
	aa = list(map(int, input().split()))
	aa.extend([0] * 4)
	bb = aa[1:]
	bb.append(0)
	dp = [0] * len(aa)
	for (i, (a, b)) in reversed(list(enumerate(zip(aa[:n], bb[:n])))):
		dp[i] = min(dp[i + 4] + a + b, dp[i + 3] + a + b, dp[i + 3] + a, dp[i + 2] + a)
	print(dp[0])


def main(arr):
	dp = []
	for i in range(len(arr) + 1):
		dp.append([-1, -1])
	dp[-1] = [0, float('inf')]
	dp[-2] = [arr[-1], 0]
	for i in range(len(arr) - 2, -1, -1):
		dp[i][0] = arr[i] + min(dp[i + 1][1], arr[i + 1] + dp[i + 2][1])
		dp[i][1] = min(dp[i + 1][0], dp[i + 2][0])
	return dp[0][0]
T = int(input())
for t in range(T):
	n = input()
	arr = [int(i) for i in input().split(' ')]
	print(main(arr))


lines = [list(map(int, line.split())) for line in [*open(0)][2::2]]
P0 = 0
P1 = 1
for a in lines:
	bosses = len(a)
	dp = [[1000000000.0 for __ in range(bosses + 2)] for _ in range(2)]
	dp[P1][0] = 0
	for boss in range(1, bosses + 1):
		dp[P0][boss] = min(dp[P0][boss], dp[P1][boss - 1] + a[boss - 1])
		dp[P1][boss] = min(dp[P1][boss], dp[P0][boss - 1])
		dp[P0][boss + 1] = min(dp[P0][boss + 1], dp[P0][boss] + a[boss - 1], dp[P1][boss - 1] + a[boss - 1])
		dp[P1][boss + 1] = min(dp[P1][boss + 1], dp[P0][boss])
	print(min(dp[P0][bosses], dp[P1][bosses]))


for _ in ' ' * int(input()):
	(n, a) = (int(input()), input().split())
	c = 0 if a[0] == '0' else 1
	print(c + ''.join(a[1:]).count('111'))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	A = alele()
	if N == 1:
		print(A[0])
	else:
		A = A + [0] * 5
		X = [0] + [1 << 30] * (N + 5)
		for i in range(2, N + 5):
			X[i] = min(X[i], X[i - 2] + A[i - 2])
			if i >= 3:
				X[i] = min(X[i], X[i - 3] + A[i - 3])
			if i >= 4:
				X[i] = min(X[i], X[i - 4] + A[i - 4] + A[i - 3])
		print(min(X[-5:]))


for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	dp = [10 ** 18 for j in range(n)]
	dp[0] = a[0]
	if n > 1:
		dp[1] = a[1] + a[0]
	for j in range(2, n):
		if j >= 2:
			dp[j] = min(dp[j], dp[j - 2] + a[j])
		if j >= 3:
			dp[j] = min(dp[j], dp[j - 3] + a[j] + a[j - 1])
		if j >= 3:
			dp[j] = min(dp[j], dp[j - 3] + a[j])
		if j >= 4:
			dp[j] = min(dp[j], dp[j - 4] + a[j] + a[j - 1])
	print(min(dp[max(0, n - 1)], dp[max(0, n - 2)], dp[max(0, n - 3)]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	count = 0
	if a[:1] == '1':
		count += 1
	a = a[2:]
	count += a.count('1 1 1')
	print(count)


import sys
input = sys.stdin.buffer.readline
INF = 10 ** 8
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split())) + [0, 0, 0]
	n = n + 3
	dp = [INF] * (n + 1)
	dp[0] = 0
	for i in range(n):
		if i + 2 <= n:
			dp[i + 2] = min(dp[i] + a[i], dp[i + 2])
		if i + 3 <= n:
			dp[i + 3] = min(dp[i] + a[i], dp[i + 3])
		if i + 4 <= n:
			dp[i + 4] = min(dp[i] + a[i] + a[i + 1], dp[i + 4])
	print(dp[-1])


import math
inf = 100000000
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(arr[0])
		continue
	ans = 0
	if arr[0] == 1:
		ans = 1
		arr[0] = 0
	cnt = 0
	for i in range(1, n):
		if arr[i] == 1:
			cnt += 1
		else:
			ans += cnt // 3
			cnt = 0
	ans += cnt // 3
	print(ans)


import itertools
import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '6\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0\n'
	for line in data.split('\n'):
		yield line
if '--debug' not in sys.argv:

	def stdinWrapper():
		while True:
			yield input()
inputs = stdinWrapper()

def inputWrapper():
	return next(inputs)

def getType(_type):
	return _type(inputWrapper())

def getArray(_type):
	return [_type(x) for x in inputWrapper().split()]

def solve(a):
	dp = [[+float('inf') for _ in range(4)] for _ in range(len(a) + 1)]
	(f1, f2, m1, m2) = range(4)
	dp[0][0] = 0
	for i in range(len(a)):
		for p in [f1, f2, m1, m2]:
			if dp[i][p] == +float('inf'):
				continue
			if p == f1:
				dp[i + 1][f2] = min(dp[i + 1][f2], dp[i][p] + a[i])
				dp[i + 1][m1] = min(dp[i + 1][m1], dp[i][p] + a[i])
			elif p == f2:
				dp[i + 1][m1] = min(dp[i + 1][m1], dp[i][p] + a[i])
			elif p == m1:
				dp[i + 1][m2] = min(dp[i + 1][m2], dp[i][p])
				dp[i + 1][f1] = min(dp[i + 1][f1], dp[i][p])
			elif p == m2:
				dp[i + 1][f1] = min(dp[i + 1][f1], dp[i][p])
	return min(dp[-1])
t = getType(int)
for _ in range(t):
	n = getType(int)
	a = getArray(int)
	print(solve(a))


for _ in range(int(input())):
	n = int(input())
	a = ''.join((i for i in input().split()))
	print((a[0] == '1') + a[1:].count('111'))


for _ in range(int(input())):
	N = int(input())
	A = [int(i) for i in input().split(' ')]
	count = A[0]
	temp = 0
	for i in range(1, N):
		if A[i] == 1:
			temp += 1
		else:
			count += temp // 3
			temp = 0
	count += temp // 3
	print(count)


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	lst1 = ''.join(map(str, lst))
	c = lst1[1:].count('111')
	if lst1[0] == '1':
		print(c + 1)
	else:
		print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	a = 0
	i = 0
	skip = 0
	while i < n:
		if l[i] == 0:
			a = 1
			i += 1
			continue
		if a == 0:
			if l[i] == 1:
				skip += 1
			i += 1
			if i < n - 1:
				if l[i + 1] == 1 and l[i] == 0:
					i += 1
			a = 1
		else:
			i += 1
			if i < n:
				if l[i] == 1:
					i += 1
			a = 0
	print(skip)


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(arr[0])
	elif n == 2:
		print(arr[0])
	else:
		dp = [[0 for i in range(n)] for j in range(2)]
		dp[1][0] = arr[0]
		dp[1][1] = arr[0] + arr[1]
		dp[0][0] = arr[0]
		dp[0][1] = dp[0][0]
		for i in range(2, n):
			for j in range(2):
				if j == 0:
					dp[0][i] = min(dp[1][i - 1], dp[1][i - 2])
				else:
					dp[1][i] = min(dp[0][i - 1] + arr[i], dp[0][i - 2] + arr[i] + arr[i - 1])
		print(min(dp[0][n - 1], dp[1][n - 1]))


def skip_points(bosses):
	count = 0
	temp = 0
	if bosses[0] == 1:
		count += 1
	for i in bosses[1:]:
		if i == 1:
			temp += 1
		else:
			count += temp // 3
			temp = 0
	return count + temp // 3
for _ in range(int(input())):
	n = int(input())
	bosses = list(map(int, input().split()))
	print(skip_points(bosses))


import math, collections

def testcase():
	n = int(input())
	a = input().split()
	ans = 0
	if a[0] == '1':
		ans += 1
	s = ''.join(a[1:])
	ans += s.count('111')
	print(ans)
t = int(input())
while t > 0:
	testcase()
	t -= 1


import sys
input = sys.stdin.readline
INF = 10 ** 9
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(item) for item in input().split()] + [1, 1]
	dp = [[INF] * (n + 5) for _ in range(2)]
	dp[1][0] = 0
	for (i, item) in enumerate(a[:n]):
		if dp[0][i] == -1:
			continue
		dp[1][i + 1] = min(dp[1][i + 1], dp[0][i])
		dp[1][i + 2] = min(dp[1][i + 2], dp[0][i])
		if dp[1][i] == -1:
			continue
		dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + a[i])
		dp[0][i + 2] = min(dp[0][i + 2], dp[1][i] + a[i] + a[i + 1])
	print(min(dp[0][n], dp[1][n]))


import sys
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, sys.stdin.readline().split()))
	if n >= 5:
		dp = [0 for i in range(n)]
		dp[0] = arr[0]
		dp[1] = arr[0]
		dp[2] = arr[0]
		dp[3] = min(arr[0] + arr[1], arr[0] + arr[2])
		dp[4] = min(dp[1] + arr[2], dp[2] + arr[3])
		for i in range(5, n):
			dp[i] = min(dp[i - 4] + arr[i - 3] + arr[i - 2], dp[i - 3] + arr[i - 2], dp[i - 2] + arr[i - 1])
		print(min(dp[n - 1], dp[n - 2] + arr[n - 1], dp[n - 3] + arr[n - 1] + arr[n - 2]))
	else:
		dp = [0, 0, 0, 0, 0]
		while len(arr) != 5:
			arr.append(0)
		dp[0] = arr[0]
		dp[1] = arr[0]
		dp[2] = arr[0]
		dp[3] = min(arr[0] + arr[1], arr[0] + arr[2], arr[0] + arr[3])
		dp[4] = min(dp[1] + arr[2], dp[2] + arr[3], dp[3] + arr[4])
		print(dp[n])


import math
for _ in range(int(input())):
	am = int(input())
	arr = list(input().split())
	ans = 0
	if arr[0] == '1':
		ans += 1
	arr = arr[1:]
	arr = ''.join(arr).split('0')
	for i in range(len(arr)):
		ans += math.floor(len(arr[i]) / 3)
	print(ans)


from collections import defaultdict

def f(i, myturn=False):
	l = n - i
	if myturn and l in me:
		return me[l]
	if not myturn and l in friend:
		return friend[l]
	if l == 0:
		return 0
	if l == 1:
		if myturn:
			return 0
		elif a[i] == 0:
			return 0
		else:
			return 1
	(x, y) = (a[i], a[i + 1])
	if myturn:
		return min(f(i + 1, not myturn), f(i + 2, not myturn))
	else:
		return min((x == 1) + f(i + 1, not myturn), (x == 1) + (y == 1) + f(i + 2, not myturn))
for _ in range(int(input())):
	me = defaultdict(int)
	friend = defaultdict(int)
	n = int(input())
	a = [int(x) for x in input().split()]
	for i in range(n - 1, -1, -1):
		me[n - i] = f(i, True)
		friend[n - i] = f(i, False)
	print(friend[n])


t = int(input())
for i in range(t):
	n = int(input())
	ls = [int(a) for a in input().split()]
	ls.append(0)
	ls.append(0)
	skp = 0
	ctr = 0
	turn = 1
	for j in range(n):
		if turn:
			if ctr == 0:
				ctr += 1
				if ls[j]:
					skp += 1
			elif ctr == 1:
				if ls[j]:
					turn = 0
					ctr = 1
				elif ls[j + 2] and ls[j + 1] == 0:
					ctr = 1
					turn = 0
				else:
					ctr += 1
			else:
				ctr = 1
				turn = 0
		elif ctr == 0:
			ctr += 1
		elif ctr == 1:
			if ls[j]:
				ctr += 1
			elif ls[j + 1]:
				ctr = 1
				turn = 1
			else:
				ctr += 1
		else:
			ctr = 1
			turn = 1
			if ls[j]:
				skp += 1
	print(skp)


INF = 10 ** 6
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	out = [0] * (n + 1)
	for i in range(1, n + 1):
		best = INF
		if i >= 2:
			best = min(best, a[i - 2] + out[i - 2])
		if i >= 3:
			best = min(best, a[i - 3] + out[i - 3])
		if i >= 4:
			best = min(best, a[i - 4] + a[i - 3] + out[i - 4])
		out[i] = best
	fin = out[n]
	for i in range(1, 4):
		if i <= n:
			fin = min(fin, out[n - i] + a[n - i])
	print(fin)


for i in range(int(input())):
	(_, l) = (input(), list(map(int, input().split(' '))))
	for i in range(1, len(l)):
		l[i] += min(l[max(0, i - 3):i])
	print(min(l[-3:]))


def solution(n, a):
	if n == 1:
		return a[0]
	dp = [[0, 0] for i in range(n)]
	(dp[n - 1], dp[n - 2]) = ([a[n - 1], 0], [a[n - 2], 0])
	for i in range(n - 3, -1, -1):
		dp[i][0] = min(a[i] + dp[i + 1][1], a[i] + a[i + 1] + dp[i + 2][1])
		dp[i][1] = min(dp[i + 1][0], dp[i + 2][0])
	return dp[0][0]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(solution(n, a))


import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n,) = _read_ints()
		a = tuple(_read_ints())
		result = find_min_pass_points_need(is_boss_hard=a)
		print(result)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split(' '))

def find_min_pass_points_need(is_boss_hard):
	bosses_n = len(is_boss_hard)
	if bosses_n == 0:
		return 0
	if bosses_n == 1:
		return 1 if is_boss_hard[0] else 0
	assert bosses_n >= 2
	cost_if_strong_player_ended = [float('inf')] * bosses_n
	cost_if_weak_player_ended = [float('inf')] * bosses_n
	cost_if_weak_player_ended[0] = 1 if is_boss_hard[0] else 0
	cost_if_weak_player_ended[1] = cost_if_weak_player_ended[0] + (1 if is_boss_hard[1] else 0)
	cost_if_strong_player_ended[1] = cost_if_weak_player_ended[0]
	for i_boss in range(2, bosses_n):
		cost_if_strong_player_ended[i_boss] = min(cost_if_weak_player_ended[i_boss - 1], cost_if_weak_player_ended[i_boss - 2])
		cost_if_weak_player_ended[i_boss] = min(cost_if_strong_player_ended[i_boss - 1] + is_boss_hard[i_boss], cost_if_strong_player_ended[i_boss - 2] + is_boss_hard[i_boss - 1] + is_boss_hard[i_boss])
	return min(cost_if_strong_player_ended[-1], cost_if_weak_player_ended[-1])
main()


INF = float('inf')

def tc():
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[INF] * 2 for _ in range(n + 1)]
	dp[0][0] = INF
	dp[0][1] = 0
	for i in range(n):
		dp[i + 1][0] = min(dp[i][1] + bool(a[i]), dp[i + 1][0])
		dp[i + 1][1] = min(dp[i][0], dp[i + 1][1])
		if i < n - 1:
			dp[i + 2][0] = min(dp[i][1] + bool(a[i]) + bool(a[i + 1]), dp[i + 2][0])
			dp[i + 2][1] = min(dp[i][0], dp[i + 2][1])
	print(min(dp[n]))
T = int(input())
for _ in range(T):
	tc()


N = int(input())

def helper(bosses, n):
	a = b = -1
	dp = [[float('inf')] * 4 for _ in range(n + 2)]
	dp[1][2] = 0
	for i in range(2, n + 2):
		dp[i][0] = min(dp[i - 1][2], dp[i - 1][3]) + bosses[i - 2]
		dp[i][1] = min(dp[i - 2][2], dp[i - 2][3]) + bosses[i - 2] + bosses[i - 3]
		dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])
		dp[i][3] = min(dp[i - 2][0], dp[i - 2][1])
	return min(dp[-1])
for _ in range(N):
	n = int(input())
	bosses = list(map(int, input().split(' ')))
	print(helper(bosses, n))


for _ in range(int(input())):
	n = int(input())
	A = [int(_) for _ in input().split()]
	ans = 0
	c = 0
	if A[0] == 1:
		ans += 1
	for _ in range(1, n):
		if A[_] == 1:
			c += 1
		else:
			ans += c // 3
			c = 0
	print(ans + c // 3)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = [0] * n
	a = [inf] * n
	b = [inf] * n
	if n == 1 or n == 2:
		print(ar[0])
	else:
		a[0] = ar[0]
		a[1] = a[0] + ar[1]
		b[1] = a[0]
		for i in range(2, n):
			a[i] = min(b[i - 1], ar[i - 1] + b[i - 2]) + ar[i]
			b[i] = min(a[i - 1], a[i - 2])
		print(min(a[-1], b[-1]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = [0]
	i = 0
	lm = 0
	if a[i] == 1:
		i += 1
		s[0] += 1
	a = a + [0]
	x = []
	ls = 0
	l = 0
	for j in range(i, n + 1):
		if a[j] == 1:
			l += 1
			ls = 1
		elif a[j] == 0 and ls == 1:
			x.append(l)
			l = 0
			ls = 0
	for i in x:
		s[0] += i // 3
	print(s[0])


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = int(1000000000.0) + 7
INF = float('inf')
for t in range(int(data())):
	n = int(data())
	a = mdata()
	dp1 = [0] * n
	dp2 = [0] * n
	dp1[0] = dp2[0] = a[0]
	if n > 1:
		dp1[1] = INF
		dp2[1] = dp2[0] + a[1]
	if n > 2:
		dp1[2] = dp1[0] + a[2]
		dp2[2] = INF
	for i in range(3, n):
		dp1[i] = min(dp1[i - 2], dp2[i - 2], dp1[i - 3], dp2[i - 3]) + a[i]
		dp2[i] = dp1[i - 1] + a[i]
	ans = INF
	for i in range(n - 1, max(n - 4, -1), -1):
		ans = min(dp1[i], dp2[i], ans)
	out(ans)


inf = int(10000000000.0)
for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if n == 1:
		print(lis[0])
		continue
	dp = [[0, 0] for i in range(n)]
	dp[0][0] = lis[0]
	dp[0][1] = inf
	dp[1][0] = lis[0] + lis[1]
	dp[1][1] = dp[0][0]
	for i in range(2, n):
		dp[i][0] = min(lis[i] + dp[i - 1][1], lis[i] + lis[i - 1] + dp[i - 2][1])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	print(min(dp[n - 1]))


t = int(input())
for w in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = 0 if a[0] == 0 else 1
	a = a[1:]
	n1 = 0
	for x in a:
		if x == 0:
			n1 = 0
		else:
			n1 += 1
			if n1 % 3 == 0:
				p += 1
	print(p)


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	g = []
	count = 0
	for i in a:
		if i:
			count += 1
		elif count:
			g.append(count)
			count = 0
	if count:
		g.append(count)
	if not g:
		print(0)
		continue
	ans = 0
	for i in range(1, len(g)):
		ans += g[i] // 3
	if a[0]:
		ans += 1 + (g[0] - 1) // 3
	else:
		ans += g[0] // 3
	print(ans)


def f(L, n):

	def cost(a, b, i):
		return L[n - i] + (L[n - i + 1] if a == 2 else 0)
	dp = [-1 for i in range(n + 1)]
	for i in range(1, n + 1):
		if i <= 3:
			dp[i] = 1 if L[n - i] == 1 else 0
		elif i == 4:
			dp[i] = min(dp[i - 2] + cost(1, 1, i), dp[i - 3] + cost(2, 1, i), dp[i - 3] + cost(1, 2, i), cost(2, 2, i))
		else:
			dp[i] = min(dp[i - 2] + cost(1, 1, i), dp[i - 3] + cost(2, 1, i), dp[i - 3] + cost(1, 2, i), dp[i - 4] + cost(2, 2, i))
	return dp[n]
for _ in range(int(input().strip())):
	N = int(input().strip())
	L = list(map(int, input().strip().split()))
	print(f(L, N))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ones = 0
	ans = arr[0]
	for i in range(1, n):
		if arr[i] == 1:
			ones += 1
		else:
			ans += ones // 3
			ones = 0
	ans += ones // 3
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(arr) == 1:
		print(arr[0])
		continue
	dp = [[int(arr[0] == 1), 1000000000.0], [1000000000.0, int(arr[0] == 1) + int(arr[1] == 1)]]
	for i in range(2, n):
		dp.append([min(dp[i - 2]) + int(arr[i] == 1)])
		if i >= 3:
			dp[i][0] = min(dp[i][0], min(dp[i - 3][0], dp[i - 3][1]) + int(arr[i] == 1))
		dp[i].append(dp[i - 1][0] + +int(arr[i] == 1))
	ans = 1000000000.0
	for i in range(n - 1, max(-1, n - 4), -1):
		ans = min(ans, min(dp[i]))
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	dp = [[10 ** 9, 10 ** 9] for i in range(n)]
	dp[0][0] = a[0]
	if n > 1:
		dp[1][0] = a[1] + dp[0][0]
		dp[1][1] = dp[0][0]
	for i in range(2, n):
		dp[i][0] = min(dp[i - 1][0] + a[i], dp[i - 1][1] + a[i], dp[i - 2][1] + a[i - 1] + a[i])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	print(min(dp[n - 1]))


import sys
sys.setrecursionlimit(3 * 10 ** 5 + 10)
from types import GeneratorType

def bootstrap(func, stack=[]):

	def wrapped_function(*args, **kwargs):
		if stack:
			return func(*args, **kwargs)
		else:
			call = func(*args, **kwargs)
			while True:
				if type(call) is GeneratorType:
					stack.append(call)
					call = next(call)
				else:
					stack.pop()
					if not stack:
						break
					call = stack[-1].send(call)
			return call
	return wrapped_function
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[-1] * 2 for i in range(n + 1)]

	@bootstrap
	def rec(i, turn):
		if i >= n:
			yield 0
		res = float('inf')
		if dp[i][turn] != -1:
			yield dp[i][turn]
		if turn:
			if i < n:
				res = min(res, a[i] + (yield rec(i + 1, turn ^ 1)))
			if i + 1 < n:
				res = min(res, a[i] + a[i + 1] + (yield rec(i + 2, turn ^ 1)))
		else:
			if i < n:
				res = min(res, (yield rec(i + 1, turn ^ 1)))
			if i + 1 < n:
				res = min(res, (yield rec(i + 2, turn ^ 1)))
		dp[i][turn] = res
		yield res
	print(rec(0, 1))


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	f = 1
	c = 0
	if X[0] == 1:
		c += 1
	z = 0
	for i in range(1, N):
		if X[i] == 0:
			z = 0
		else:
			z += 1
		if z == 3:
			c += 1
			z = 0
	print(c)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	cnt = 0
	i = 0
	a.append(0)
	a.append(0)
	a.append(0)
	a.append(0)
	while i < n:
		if a[i] == 1:
			cnt += 1
		i += 1
		if a[i] == 0:
			i += 1
		if a[i] == 1:
			i += 1
		if a[i] == 1:
			i += 1
	print(cnt)


import sys
readline = sys.stdin.readline

def inlt():
	return list(map(int, readline().split()))

def ingen():
	return map(int, readline().split())

def insr():
	s = readline()
	return list(s)

def inn():
	return int(readline())
N = inn()
for i in range(N):
	M = inn()
	rooms = inlt()
	dp = [[0 for i in range(M + 1)] for j in range(2)]
	dp[0][0] = 0
	dp[1][0] = float('inf')
	for i in range(1, M + 1):
		dp[0][i] = min(dp[1][i - 1], dp[1][i - 2] if i - 2 >= 0 else float('inf'))
		v1 = dp[0][i - 1] + (1 if rooms[i - 1] == 1 else 0)
		v2 = float('inf')
		if i - 2 >= 0:
			v2 = dp[0][i - 2] + (1 if rooms[i - 1] == 1 else 0) + (1 if rooms[i - 2] == 1 else 0)
		dp[1][i] = min(v1, v2)
	print(min(dp[0][-1], dp[1][-1]))


for t in range(int(input())):
	n = int(input())
	v = [0] + list(map(int, input().split()))
	d = [[1 << 30] * 2 for i in range(n + 1)]
	d[0][0] = 0
	for i in range(1, n + 1):
		d[i][1] = min(d[i][1], d[i - 1][0] + v[i])
		d[i][0] = min(d[i][0], d[i - 1][1])
		if i - 1 >= 0:
			d[i][1] = min(d[i][1], d[i - 2][0] + v[i - 1] + v[i])
			d[i][0] = min(d[i][0], d[i - 2][1])
	print(min(d[n]))


import math
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[0, 0] for i in range(n + 1)]
	for i in range(n - 1, -1, -1):
		dp[i][0] = dp[i + 1][1] + a[i]
		if i + 1 < n:
			dp[i][0] = min(dp[i + 2][1] + a[i] + a[i + 1], dp[i][0])
		dp[i][1] = dp[i + 1][0]
		if i + 1 < n:
			dp[i][1] = min(dp[i][1], dp[i + 2][0])
	print(dp[0][0])
	t -= 1


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	A = LIST()
	dp0 = [INF] * (N + 1)
	dp1 = [INF] * (N + 1)
	dp0[0] = 0
	for i in range(N):
		dp1[i + 1] = min(dp1[i + 1], dp0[i] + A[i])
		dp0[i + 1] = min(dp0[i + 1], dp1[i])
		if i < N - 1:
			dp1[i + 2] = min(dp1[i + 2], dp0[i] + A[i] + A[i + 1])
			dp0[i + 2] = min(dp0[i + 2], dp1[i])
	ans = min(dp0[N], dp1[N])
	print(ans)


from sys import stdin, stdout
import math
from bisect import bisect_right
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def pr(a):
	return ''.join(list(map(str, a)))

def solve():
	n = I()
	a = L()
	b = pr(a).split('0')
	c = []
	for i in b:
		if i:
			c += [len(i)]
	if not c:
		print(0)
		return
	ans = 0
	if a[0] == 1:
		ans += max(1, (c[0] + 2) // 3)
	else:
		ans += c[0] // 3
	for i in range(1, len(c)):
		ans += c[i] // 3
	print(ans)
for _ in range(I()):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	if lst[0] == 0:
		c = 0
		ind = 0
		while True:
			if ind > n - 1:
				break
			elif lst[ind] == 1:
				c1 = 1
				ind1 = 0
				for j in range(ind + 1, n):
					if lst[j] == 1:
						c1 += 1
						ind1 += 1
					else:
						break
				ind = ind + ind1 + 1
				c += c1 // 3
			else:
				ind += 1
		print(c)
	else:
		lst = lst[1:]
		c = 1
		ind = 0
		while True:
			if ind > n - 2:
				break
			elif lst[ind] == 1:
				c1 = 1
				ind1 = 0
				for j in range(ind + 1, n - 1):
					if lst[j] == 1:
						c1 += 1
						ind1 += 1
					else:
						break
				ind = ind + ind1 + 1
				c += c1 // 3
			else:
				ind += 1
		print(c)


import math
tests = int(input())
for testnum in range(tests):
	n = int(input())
	numbers = map(int, input().split())
	numbers = list(numbers)
	medp = [-1] * n
	yudp = [-1] * n
	if n == 1 or n == 2:
		print(numbers[0])
		continue
	else:
		yudp[0] = numbers[0]
		yudp[1] = numbers[0] + numbers[1]
		medp[1] = yudp[0]
		for i in range(2, n):
			medp[i] = min(yudp[i - 1], yudp[i - 2])
			if medp[i - 2] >= 0:
				yudp[i] = min(medp[i - 1] + numbers[i], medp[i - 2] + numbers[i] + numbers[i - 1])
			else:
				yudp[i] = medp[i - 1] + numbers[i]
	print(min(yudp[n - 1], medp[n - 1]))


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(lst):
	console('----- solving ------')
	if len(lst) <= 2:
		return lst[0]
	dp = [[10 ** 10, 10 ** 10] for _ in lst]
	if lst[0] == 0:
		dp[0][0] = 0
	else:
		dp[0][0] = 1
	if lst[1] == 0:
		dp[1][0] = 0 + dp[0][0]
	else:
		dp[1][0] = 1 + dp[0][0]
	dp[1][1] = dp[0][0]
	for i in range(2, len(lst)):
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
		dp[i][0] = min(dp[i - 1][1] + lst[i], dp[i - 2][1] + lst[i] + lst[i - 1])
	return min(dp[-1][1], dp[-1][0])

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
inp = sys.stdin.readlines()
for case_num in range(int(inp[0])):
	lst = list(map(int, inp[2 * case_num + 2].split()))
	res = solve(lst)
	print(res)


INF = float('inf')

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[[INF] * (n + 1) for _ in range(2)] for _ in range(2)]
	dp[0][1][0] = 0
	for i in range(n):
		dp[0][0][i + 1] = min(dp[1][0][i], dp[1][1][i])
		dp[0][1][i + 1] = dp[0][0][i]
		dp[1][1][i + 1] = dp[1][0][i] + a[i]
		dp[1][0][i + 1] = min(dp[0][0][i], dp[0][1][i]) + a[i]
	ans = INF
	for t in range(2):
		for p in range(2):
			ans = min(ans, dp[t][p][n])
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for t in range(int(input())):
	n = int(input())
	A = [int(i) for i in input().split()]
	A.append(0)
	count = 0
	if A[0] == 1:
		count += 1
	o = 0
	for i in range(1, n + 1):
		if A[i] == 1:
			o += 1
		else:
			count += o // 3
			o = 0
	print(count)


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	temparr = input()
	temparr = temparr.split()
	arr = []
	for i in temparr:
		arr.append(int(i))
	ans = 0
	fflag = 0
	prevcount = 0
	for i in range(n):
		if prevcount == 0 and fflag == 0 and (arr[i] == 1):
			ans += 1
			prevcount = 1
		elif prevcount == 0 and fflag == 0 and (arr[i] == 0):
			prevcount = 1
		elif prevcount == 1 and fflag == 0 and (arr[i] == 0):
			fflag = 1
			prevcount = 0
		elif prevcount == 1 and fflag == 0 and (arr[i] == 1):
			fflag = 1
		elif fflag == 1 and arr[i] == 1 and (prevcount == 1):
			fflag = 0
			prevcount = 0
		elif fflag == 1 and arr[i] == 1 and (prevcount == 0):
			prevcount = 1
		elif fflag == 1 and arr[i] == 0:
			prevcount = 1
			fflag = 0
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	if l[0] == 1:
		ans += 1
	i = 1
	while i < n:
		if l[i] == 0:
			i += 1
			continue
		j = i
		while j < n and l[j] == 1:
			j += 1
		ans += (j - i) // 3
		i = j - 1
		i += 1
	print(ans)


import sys
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

@bootstrap
def solve(i, f):
	if dp[i][f] != -1:
		yield dp[i][f]
	elif f == 0:
		if i > n - 3:
			k = 0
		else:
			k1 = (yield solve(i + 1, f ^ 1))
			k2 = (yield solve(i + 2, f ^ 1))
			k = min(k1, k2)
		dp[i][f] = k
		yield k
	else:
		if i > n - 3:
			k = l[i]
		else:
			k1 = (yield solve(i + 1, f ^ 1))
			k1 = k1 + l[i]
			k2 = (yield solve(i + 2, f ^ 1))
			k2 = k2 + l[i + 1] + l[i]
			k = min(k1, k2)
		dp[i][f] = k
		yield k
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	dp = []
	for i in range(n):
		dp.append([-1, -1])
	if l[-1] == 0:
		dp[n - 1] = [0, 0]
	else:
		dp[n - 1] = [0, 1]
	print(solve(0, 1))


inf = 1 << 30

def work():
	n = int(input())
	a = [int(i) for i in input().split()]
	if n <= 3:
		print(a[0])
		return
	dp = [[inf] * (n + 1), [inf] * (n + 1)]
	dp[1][0] = 0
	dp[0][0] = inf
	dp[1][1] = inf
	dp[0][1] = a[0]
	dp[1][2] = dp[0][1]
	dp[0][2] = a[0] + a[1]
	for i in range(2, n):
		j = i + 1
		dp[0][j] = min(dp[1][j - 1] + a[i], dp[1][j - 2] + a[i] + a[i - 1])
		dp[1][j] = min(dp[0][j - 1], dp[0][j - 2])
	print(min(dp[0][n], dp[1][n]))

def main():
	t = int(input())
	while t > 0:
		work()
		t -= 1
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

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

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())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

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

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict
sys.setrecursionlimit(300000)

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
from math import factorial

def solve():
	n = N()
	s = '1 1 ' + inp()
	print(s.count('1 1 1'))
testcase(int(inp()))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 3:
		print(a[0])
	else:
		dp = [[0] * n for i in range(2)]
		dp[0][0] = a[0]
		dp[1][0] = a[0]
		dp[0][1] = a[0]
		dp[1][1] = a[0] + a[1]
		dp[0][2] = min(dp[1][0], dp[1][1])
		dp[1][2] = a[2] + dp[0][1]
		for i in range(3, n):
			dp[0][i] = min(dp[1][i - 1], dp[1][i - 2])
			dp[1][i] = a[i] + min(dp[0][i - 1], a[i - 1] + dp[0][i - 2])
		print(min(dp[0][-1], dp[1][-1]))


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	if n >= 2:
		if arr[0] == 1 and arr[1] == 1:
			ans += 1
			i = 1
		elif arr[0] == 0 and arr[1] == 1:
			i = 1
		else:
			if arr[0]:
				ans += 1
			i = 2
		while i < n:
			if i + 2 < n:
				if arr[i] == 1 and arr[i + 1] == 1 and (arr[i + 2] == 1):
					ans += 1
					i += 3
					continue
				i += 1
			else:
				break
	elif arr[0]:
		ans = 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	dp00 = [None for x in range(n)]
	dp01 = [None for x in range(n)]
	dp11 = [None for x in range(n)]
	dp10 = [None for x in range(n)]
	dp00[0] = a[0]
	dp10[0] = a[0]
	for (i, boss) in enumerate(a):
		if i == 0:
			continue
		if i > 3:
			dp00[i] = boss + dp10[i - 1]
			dp01[i] = min(dp00[i - 1], dp10[i - 1])
			dp10[i] = boss + min(dp01[i - 1], dp11[i - 1])
			dp11[i] = dp01[i - 1]
		if i == 1:
			dp01[i] = a[0]
			dp00[i] = a[0] + a[1]
		if i == 2:
			dp11[i] = dp01[i - 1]
			dp01[i] = dp00[i - 1]
			dp10[i] = a[i] + dp01[i - 1]
		if i == 3:
			dp11[i] = dp01[i - 1]
			dp00[i] = boss + dp10[i - 1]
			dp10[i] = boss + min(dp01[i - 1], dp11[i - 1])
			dp01[i] = dp10[i - 1]
	if n > 3:
		ans = min(dp00[n - 1], dp10[n - 1], dp01[n - 1], dp11[n - 1])
	if n == 1:
		ans = a[0]
	if n == 2:
		ans = a[0]
	if n == 3:
		ans = a[0]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	i = 0
	ct = 'f'
	ans = 0
	while i < n:
		if ct == 'f':
			if p[i] == 0:
				if i + 1 < n and p[i + 1] == 0:
					if i + 2 < n and p[i + 2] == 0:
						i += 1
					else:
						i += 2
				else:
					i += 1
			else:
				ans += 1
				if i + 1 < n and p[i + 1] == 0:
					if i + 2 < n and p[i + 2] == 0:
						i += 1
					else:
						i += 2
				else:
					i += 1
			ct = 'm'
		else:
			if i + 1 < n and p[i + 1] == 0:
				if i + 2 < n and p[i + 2] == 0:
					i += 2
				else:
					i += 1
			else:
				i += 2
			ct = 'f'
	print(ans)


ans = []

def solve():
	global ans
	n = int(input())
	(*a,) = map(int, input().split())
	if n == 1:
		ans.append(a[0])
		return
	dp0 = [0] * n
	dp0[-1] = a[-1]
	dp0[-2] = a[-2]
	dp1 = [0] * n
	for i in range(n - 3, -1, -1):
		dp0[i] = min(dp1[i + 1] + a[i], dp1[i + 2] + a[i] + a[i + 1])
		dp1[i] = min(dp0[i + 1], dp0[i + 2])
	ans.append(dp0[0])
t = int(input())
for i in range(t):
	solve()
for ai in ans:
	print(ai)


t = int(input())
for _ in range(t):
	n = int(input())
	v = list(map(int, input().split()))
	dp = [[0 for i in range(n)] for j in range(2)]
	dp[0][n - 1] = 0
	dp[1][n - 1] = v[n - 1]
	for i in range(n - 2, -1, -1):
		if i == n - 2:
			dp[1][n - 2] = min(v[n - 2] + dp[0][n - 1], v[n - 2] + v[n - 1])
			dp[0][n - 2] = 0
		else:
			dp[1][i] = min(v[i] + dp[0][i + 1], v[i] + v[i + 1] + dp[0][i + 2])
			dp[0][i] = min(dp[1][i + 1], dp[1][i + 2])
	print(dp[1][0])


n = int(input())
for i in range(n):
	l = int(input())
	data = [int(i) for i in input().split()]
	skip = 0
	i = 0
	while l > i:
		if data[i] == 1:
			skip += 1
		i += 1
		if i < l and data[i] == 0 and (not (i + 1 < l and data[i + 1] == 0)):
			i += 1
		i += 1
		if i < l and data[i] == 1:
			i += 1
	print(skip)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = 0
	if lis[0] == 1:
		ans = 1
	c = 0
	for i in range(1, len(lis)):
		if lis[i] == 1:
			c += 1
		else:
			ans += c // 3
			c = 0
	ans += c // 3
	print(ans)


import sys

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

def list_input():
	return list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	n = int(input())
	a = list_input()
	li = []
	if a[0] == 1:
		i = 1
	else:
		i = 0
	while i < n:
		c = 0
		if a[i] == 0:
			while i < n and a[i] == 0:
				i += 1
		else:
			while i < n and a[i] == 1:
				c += 1
				i += 1
			li.append(c)
	ans = 0
	for i in li:
		ans += i // 3
	if a[0] == 1:
		ans += 1
	print(ans)


q = []
t = int(input())
for j in range(t):
	n = int(input())
	l = list(input().split(' '))
	l = [int(j) for j in l]
	skip = 0
	i = 1
	if l[0] == 1:
		skip += 1
	while i < n - 2:
		if l[i] == 1 and l[i + 1] == 1 and (l[i + 2] == 1):
			skip += 1
			i += 3
		else:
			i += 1
	q.append(skip)
for i in q:
	print(i)


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math
import random
import sys

def calc(A, L):
	for i in range(len(A)):
		for j in range(i + 1, len(A)):
			if L[i] + L[j] == 0:
				if A[i] < A[j]:
					(A[i], A[j]) = (A[j], A[i])
	print(*A)
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	him = [0] * (n + 1)
	us = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		him[i] = us[i + 1] + A[i]
		if i + 2 <= n:
			him[i] = min(him[i], us[i + 2] + A[i + 1] + A[i])
		us[i] = him[i + 1]
		if i + 2 <= n:
			us[i] = min(us[i], him[i + 2])
	print(him[0])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[float('inf') for _ in ' ' * 2] for _ in range(n + 1)]
	dp[0][1] = 0
	for i in range(n):
		for j in range(2):
			for fight in range(1, min(n - i, 2) + 1):
				hard = a[i]
				if fight > 1:
					hard += a[i + 1]
				dp[i + fight][j] = min(dp[i + fight][j], dp[i][not j] + [0, 1][j == 0] * hard)
	print(min(dp[n][0], dp[n][1]))


from sys import stdin

def input():
	return stdin.readline().rstrip()
for _ in range(int(input())):
	L = int(input())
	s = input().split()
	(res, streak) = (0, 0)
	for (i, c) in enumerate(s):
		if i == 0:
			res += c == '1'
		elif c == '1':
			streak += 1
		else:
			res += streak // 3
			streak = 0
	res += streak // 3
	print(res)


import sys
input = sys.stdin.readline
INF = 10 ** 9

def solution():
	n = int(input())
	A = list(map(int, input().split()))
	if n <= 3:
		print(A[0])
		return
	DP = [INF] * (n + 1)
	DP[0] = 0
	for i in range(2, n + 1):
		DP[i] = min(DP[i], DP[i - 2] + A[i - 2])
		if i > 2:
			DP[i] = min(DP[i], DP[i - 3] + A[i - 3])
			DP[i] = min(DP[i], DP[i - 3] + A[i - 3] + A[i - 2])
		if i > 3:
			DP[i] = min(DP[i], DP[i - 4] + A[i - 4] + A[i - 3])
	print(min(DP[-1], DP[-2] + A[-1], DP[-3] + A[-1] + A[-2]))
T = int(input())
for _ in range(T):
	solution()


for haaghfj in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[100000000000000] * 2 for i in range(n + 2)]
	dp[0][0] = 0
	for i in range(1, n + 1):
		dp[i][0] = min(dp[i - 1][1], dp[i - 2][1])
		dp[i][1] = min(dp[i - 1][0] + a[i - 1], dp[i - 2][0] + a[i - 1] + a[i - 2])
	print(min(dp[n]))


from math import ceil

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		enemies = list(map(int, input().split()))
		j = 0
		c = 1
		ans = 0
		while j < n:
			if c:
				c = 0
				if enemies[j] == 1:
					ans += 1
					j += 1
				if j < n and enemies[j] == 0:
					j += 1
			else:
				c = 1
				if enemies[j] == 1:
					j += 1
				if j < n and enemies[j] == 1:
					j += 1
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()] + [0]
	him = [0] * (n + 2)
	us = [0] * (n + 2)
	for i in range(n - 1, -1, -1):
		him[i] = min(us[i + 1] + a[i], us[i + 2] + a[i] + a[i + 1])
		us[i] = min(him[i + 1], him[i + 2])
	print(him[0])


cases = int(input())
for case in range(cases):
	bosses = int(input())
	difficulties = list(reversed([int(x) for x in input().split()]))
	melastn = [float('inf')] * (bosses + 1)
	friendlastn = [float('inf')] * (bosses + 1)
	(melastn[0], friendlastn[0]) = (0, 0)
	for index in range(bosses + 1):
		try:
			melastn[index + 1] = min(friendlastn[index], melastn[index + 1])
		except IndexError:
			pass
		try:
			melastn[index + 2] = min(friendlastn[index], melastn[index + 2])
		except IndexError:
			pass
		try:
			friendlastn[index + 1] = min(difficulties[index] + melastn[index], friendlastn[index + 1])
		except IndexError:
			pass
		try:
			friendlastn[index + 2] = min(difficulties[index] + difficulties[index + 1] + melastn[index], friendlastn[index + 2])
		except IndexError:
			pass
	print(friendlastn[-1])


t = int(input())
for i in range(t):
	n = int(input())
	s = '1 1 ' + input()
	print(s.count('1 1 1'))


for _ in range(int(input())):
	n = int(input())
	arr = [int(el) for el in input().split()]
	him = [0] * (n + 1)
	us = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		him[i] = us[i + 1] + arr[i]
		if i + 2 <= n:
			him[i] = min(him[i], us[i + 2] + arr[i] + arr[i + 1])
		us[i] = him[i + 1]
		if i + 2 <= n:
			us[i] = min(us[i], him[i + 2])
	print(him[0])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [999999999999] * (n + 10)
	dp[-1] = 0
	dp[-2] = 0
	dp[-3] = 0
	dp[-4] = 0
	dp[-5] = 0
	for i in range(n):
		if i > 0:
			l2 = arr[i - 1]
			dp[i] = min(dp[i - 2] + l2, dp[i])
		if i > 1:
			l3 = arr[i - 2]
			dp[i] = min(dp[i - 3] + l3, dp[i])
		if i > 2:
			l4 = arr[i - 2] + arr[i - 3]
			dp[i] = min(dp[i - 4] + l4, dp[i])
		if i == n - 1:
			dp[i] = min(dp[i], dp[i - 1] + arr[i])
	if n < 4:
		print(arr[0])
	else:
		print(dp[n - 1])


tests = int(input())
for t in range(tests):
	n = int(input())
	ls = list(map(int, input().split()))
	first = True
	curr_one = 0
	res = 0
	for (idx, item) in enumerate(ls):
		if item == 1:
			curr_one += 1
		if item == 0:
			if curr_one > 0:
				if first:
					res += (curr_one + 2) // 3
				else:
					res += curr_one // 3
				curr_one = 0
			first = False
	if curr_one > 0:
		if first:
			res += (curr_one + 2) // 3
		else:
			res += curr_one // 3
		curr_one = 0
	print(res)


import sys
from copy import *
from bisect import *

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	dp = [[10 ** 18, 10 ** 18] for i in range(n + 1)]
	dp[n] = [0, 0]
	for i in range(n):
		if i == 0:
			dp[i][1] = int(a[i] == 1)
		else:
			dp[i][0] = dp[i - 1][1]
			dp[i][1] = dp[i - 1][0] + int(a[i] == 1)
			if i >= 1:
				if i >= 2:
					dp[i][0] = min(dp[i][0], dp[i - 2][1])
				dp[i][1] = min(dp[i][1], dp[i - 2][0] + a[i - 1:i + 1].count(1))
	print(min(dp[n - 1]))


from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()

def getVal(i, arr):
	return arr[i] if i < n else 0
for _ in range(t):
	(n,) = gil()
	a = gil()
	dp = [0] * n
	dp[-1] = a[-1]
	for i in reversed(range(n - 1)):
		v1 = a[i] + getVal(i + 1, a) + min(getVal(i + 3, dp), getVal(i + 4, dp))
		v2 = a[i] + min(getVal(i + 2, dp), getVal(i + 3, dp))
		dp[i] = min(v1, v2)
	print(dp[0])


t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] + list(map(int, input().split()))
	dp = [[float('inf') for i in range(2)] for j in range(n + 1)]
	if n == 1:
		print(a[1])
		continue
	dp[1][0] = a[1]
	dp[0][0] = 0
	dp[0][1] = 0
	for i in range(2, n + 1):
		if i == 2:
			dp[i][0] = a[1] + a[2]
			dp[i][1] = dp[i - 1][0]
			continue
		for j in range(2):
			if j == 0:
				if dp[i - 1][j ^ 1] != 300000:
					dp[i][j] = min(dp[i][j], dp[i - 1][j ^ 1] + a[i])
				if dp[i - 2][j ^ 1] != 300000:
					dp[i][j] = min(dp[i][j], dp[i - 2][j ^ 1] + a[i] + a[i - 1])
			else:
				dp[i][j] = min(dp[i - 1][j ^ 1], dp[i - 2][j ^ 1])
	print(min(dp[n]))


testcase = int(input())
levels = []
for t_itr in range(0, testcase):
	x = input()
	levels.append(input().split())
skip = []
list_count = -1
for list in levels:
	friend_count = 0
	count = 0
	skip.append(0)
	list_count = list_count + 1
	for i in range(0, len(list)):
		if i == 0:
			friend_count += 1
			if list[i] == '1':
				skip[list_count] += 1
			if i + 2 < len(list) and list[i + 2] == '0':
				list[i + 1] = '1'
		elif list[i] == '0' and friend_count < 2 or (list[i] == '1' and count == 2):
			if i + 2 < len(list) and list[i + 2] == '0':
				list[i + 1] = '1'
			count = 0
			friend_count += 1
			if list[i] == '1':
				skip[list_count] += 1
		else:
			friend_count = 0
			count += 1
for num in skip:
	print(num)


for _ in range(int(input())):
	n = int(input())
	a = n
	b = n
	c = n
	d = 0
	for A in map(int, input().split()):
		if A:
			(a, b, c, d) = (min(c + 1, d + 1), a + 1, min(a, b), c)
		else:
			(a, b, c, d) = (min(c, d), a, min(a, b), c)
	print(min(a, b, c, d))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	cnt = 0
	if a[0] == 1:
		ans += 1
	for j in range(1, n):
		if a[j] == 1:
			cnt += 1
		else:
			cnt = 0
		if cnt == 3:
			ans += 1
			cnt = 0
	print(ans)


import sys
import re

def solve():
	n = int(input())
	s = input()
	s = ''.join(s.split())
	c = s.count('111', 1, len(s))
	print(c if s[0] == '0' else c + 1)
n = int(input())
while n:
	solve()
	n -= 1


def findNumPoints(n, a):
	skips = 0
	if a[0] == 1:
		skips += 1
	i = 1
	while i < n:
		if a[i] == 1:
			k = 0
			while i < n and a[i] == 1:
				i += 1
				k += 1
			skips += k // 3
		else:
			i += 1
	return skips
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(findNumPoints(n, a))


import sys
input = sys.stdin.readline

def One(type):
	return type(input())

def List(type):
	return list(map(type, input().split()))

def Str():
	ans = list(input())
	ans.pop()
	return ans

def Many(type):
	return map(type, input().split())

def solve():
	n = One(int)
	al = List(int)
	ans = 0
	i = -1
	fr = True
	while i + 1 < n:
		i += 1
		if fr:
			if al[i] == 1:
				ans += 1
			j = i + 1
			while j < n and al[j] == 0:
				j += 1
			i = j - 1
		elif i < n - 1:
			if al[i] == 1 and al[i + 1] == 1:
				i = i + 1
		fr = not fr
	print(ans)

def main():
	t = One(int)
	for _ in range(t):
		solve()
main()


R = lambda : map(int, input().split())
(t,) = R()
for _ in range(t):
	n = int(input())
	arr = list(R())
	arr.append(0)
	skip_count = arr[0]
	b = 0
	for i in range(1, n + 1):
		if arr[i] == 0:
			skip_count += b // 3
			b = 0
		else:
			b += 1
	print(skip_count)


import sys

def solution():
	T = int(input())
	for _ in range(T):
		int(input())
		arr = ''.join(input().split())
		result = 0
		if arr[0] == '1':
			result += 1
		arr = arr[1:]
		result += arr.count('111')
		print(result)
solution()


t = int(input())
w = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(0)
	ff = a[0]
	a[0] = 0
	if sum(a) == n:
		w.append(n // 3)
	else:
		c = []
		d = 0
		summ = 0
		for i in range(n + 1):
			if a[i] == 1:
				d = d + 1
			else:
				c.append(d)
				d = 0
		for i in c:
			summ = summ + i // 3
		w.append(summ + ff)
for i in w:
	print(i)


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
INF = 10 ** 18
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	dp = [INF] * (n + 1)
	dp[0] = 0
	for i in range(n):
		c = 0
		if A[i] == 1:
			c += 1
		dp[min(n, i + 2)] = min(dp[min(n, i + 2)], dp[i] + c)
		dp[min(n, i + 3)] = min(dp[min(n, i + 3)], dp[i] + c)
		if i + 1 <= n - 1:
			if A[i + 1] == 1:
				c += 1
			dp[min(n, i + 3)] = min(dp[min(n, i + 3)], dp[i] + c)
			dp[min(n, i + 4)] = min(dp[min(n, i + 4)], dp[i] + c)
	print(dp[-1])


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


t = int(input())
for i in range(0, t):
	sum = 0
	cnt = 0
	n = int(input())
	lst = list(map(str, input().split()))
	if lst[0] == '1':
		cnt = cnt + 1
	s = ''.join(lst[1:])
	print(cnt + s.count('111'))


for i in range(int(input())):
	n = int(input())
	l = [int(j) for j in input().split(' ')]
	l.extend([0, 0])
	dp = [0] * (n + 4)
	for j in range(n - 1, -1, -1):
		dp[j] = min(dp[j + 2] + l[j], dp[j + 3] + l[j], dp[j + 4] + l[j] + l[j + 1])
	print(dp[0])


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
from itertools import product
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	a.append(0)
	co = 0
	if a[0] == 1:
		co += 1
	o = 0
	for i in range(1, n + 1):
		if a[i] == 1:
			o += 1
		else:
			co += o // 3
			o = 0
	print(co)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(200000.0 + 100)
	if n == 1:
		print((a[0] == 1) * 1)
		continue
	f = [[m] * n for i in range(2)]
	f[0][0] = (a[0] == 1) * 1
	f[0][1] = (a[0] == 1) * 1 + (a[1] == 1) * 1
	f[1][1] = f[0][0]
	for i in range(2, n):
		(p, q, r, s) = (m, m, m, m)
		p = f[1][i - 1] + (a[i] == 1)
		q = f[0][i - 2]
		s = f[1][i - 2] + (a[i] == 1) + (a[i - 1] == 1)
		r = f[0][i - 1]
		f[0][i] = min(p, s)
		f[1][i] = min(r, q)
	print(min(f[0][n - 1], f[1][n - 1]))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a_vec = input().split(' ')
	a_vec = [int(a) for a in a_vec]
	dp = [[math.inf, math.inf] for i in range(n + 1)]
	dp[0][1] = 0
	for i in range(n):
		for w in range(2):
			for f in range(1, min(n - i, 2) + 1):
				d = 0
				if f > 1:
					d = a_vec[i + 1]
				h = a_vec[i] + d
				index = 0
				if w == 0:
					index = 1
				dp[i + f][index] = min(dp[i + f][index], dp[i][w] + w * h)
	print(min(dp[n][0], dp[n][1]))


import sys
import math
from bisect import bisect_right as br
from statistics import mode
from itertools import combinations as cb

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

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	cnt = 0 if arr[0] != 1 else 1
	one_c = 0
	for i in range(1, n):
		if arr[i] == 0:
			one_c = 0
		else:
			one_c += 1
		if one_c == 3:
			cnt += 1
			one_c = 0
	print(cnt)


def ans(a, n):
	i = 0
	skip = 0
	j = 0
	if a[i] == 1:
		skip += 1
	i += 1
	j += 1
	while i < n:
		j = i
		while j < n and a[j] == 1:
			j += 1
		k = j - i
		skip += k // 3
		if i != j:
			i = j
		else:
			i += 1
	return skip
m = int(input())
for i in range(m):
	n = int(input())
	arr = input().split()
	a = []
	for i in arr:
		a.append(int(i))
	print(ans(a, n))


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	dp = [[10000000, 0] for i in range(n)]
	s = [0] * n
	for i in range(n):
		s[i] = s[i - 1] + a[i]
	for i in range(n):
		if i:
			dp[i][0] = min(dp[i][0], s[i - 1] - dp[i - 1][1] + a[i])
			dp[i][1] = max(dp[i][1], s[i - 1] - dp[i - 1][0] + a[i])
		else:
			dp[i][0] = min(dp[i][0], a[i])
		if i > 1:
			dp[i][0] = min(dp[i][0], s[i - 2] - dp[i - 2][1] + a[i] + a[i - 1])
			dp[i][1] = max(dp[i][1], s[i - 2] - dp[i - 2][0] + a[i] + a[i - 1])
		elif i == 1:
			dp[i][0] = min(dp[i][0], a[i] + a[i - 1])
	print(min(dp[n - 1][0], s[n - 1] - dp[n - 1][1]))


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '7\n8\n1 0 1 1 0 1 1 1\n5\n1 1 1 1 0\n7\n1 1 1 1 0 0 1\n6\n1 1 1 1 1 1\n1\n1\n1\n0\n5\n1 0 1 1 1'.split('\n')
for _ in range(i2i()):
	n = i2i()
	hard = mbs(mis())
	curr_hard_in_a_row = 0
	hard_groups = []
	for h in hard[1:]:
		if h:
			curr_hard_in_a_row += 1
		else:
			hard_groups.append(curr_hard_in_a_row)
			curr_hard_in_a_row = 0
	hard_groups.append(curr_hard_in_a_row)
	ans = sum((floor(group / 3) for group in hard_groups)) + int(hard[0])
	print(ans)


import sys
from functools import lru_cache
y = sys.stdin.readline
for _ in range(int(y())):
	n = int(input())
	a = [*map(int, y().split())][::-1]
	m = [(0, 0), (0, a[0])]
	for i in range(2, n + 1):
		m.append((min(m[-1][1], m[-2][1]), min(m[-1][0] + a[i - 1], m[-2][0] + a[i - 1] + a[i - 2])))
	print(m[-1][1])


from math import floor
t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	ans = array[0]
	i = 1
	while i < n:
		j = i
		while array[j] == 1:
			j += 1
			if j == n:
				break
		ans += floor((j - i) / 3)
		i = j + 1
	print(ans)


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	n = int(ii())
	data = idata()
	d = 1
	ans = 0
	if data[0] == 1:
		ans += 1
		d = 0
	for i in range(1, n):
		if data[i] == data[i - 1]:
			d += 1
		else:
			if data[i - 1] == 1:
				ans += d // 3
			d = 1
	if data[-1] == 1:
		ans += d // 3
	print(ans)
	return
for t in range(int(ii())):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 1
	ans = 0
	if arr[0] == 1:
		ans += 1
	while i != n:
		if arr[i] == 0:
			i += 1
			continue
		temp = i
		while temp != n and arr[temp] == 1:
			temp += 1
		ans += (temp - i) // 3
		i = temp
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if n == 1:
		print(a[0])
	else:
		dp = [[1000000000.0, 1000000000.0] for _ in range(n)]
		dp[0][1] = a[0]
		dp[1][0] = a[0]
		dp[1][1] = a[0] + a[1]
		for i in range(2, n):
			dp[i][0] = min(dp[i - 1][1], dp[i - 2][1])
			dp[i][1] = min(dp[i - 1][0] + a[i], dp[i - 2][0] + a[i] + a[i - 1])
		print(min(dp[-1][0], dp[-1][1]))


t = int(input())
for _ in range(t):
	n = int(input())
	li = [int(i) for i in input().split()]
	d1 = []
	d0 = []
	if n == 1:
		print(li[0])
		continue
	d0.append(li[0])
	d0.append(li[1] + li[0])
	d1.append(9999999999999999)
	d1.append(li[0])
	for i in range(2, n):
		d1.append(min(d0[i - 1], d0[i - 2]))
		d0.append(min(d1[i - 1] + li[i], d1[i - 2] + li[i - 1] + li[i]))
	print(min(d1[-1], d0[-1]))


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
from itertools import permutations as permu

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = 1
num = int(z())
for _ in range(num):
	n = int(z())
	arr = zzz()
	ans = 0
	if arr[0] == 1:
		ans += 1
	t = 0
	for i in range(1, n):
		if arr[i] == 1:
			t += 1
			if t > 2:
				ans += 1
				t = 0
		else:
			t = 0
	print(ans)


def schet():
	n = int(input())
	string = input()
	string = string.replace(' ', '')
	a = 0
	if string[0] == '1':
		a += 1
	i = 1
	while i < n:
		if string[i:i + 3] == '111':
			a += 1
			i += 3
		else:
			i += 1
	print(a)
t = int(input())
for i in range(t):
	schet()


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(a) for a in input().split()] + [0] * 5
	X = [0] + [1 << 30] * (N + 5)
	for i in range(2, N + 5):
		X[i] = min(X[i], X[i - 2] + A[i - 2])
		if i >= 3:
			X[i] = min(X[i], X[i - 3] + A[i - 3])
		if i >= 4:
			X[i] = min(X[i], X[i - 4] + A[i - 4] + A[i - 3])
	print(min(X[-5:]))


for _ in range(int(input())):
	input()
	arr = '1 1 ' + input()
	print(arr.count('1 1 1'))


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()
	dp = [[10 ** 9] * 2 for i in range(n)]
	dp[0][1] = a[0]
	if n >= 2:
		dp[1][1] = a[0] + a[1]
	for i in range(n - 1):
		for j in range(2):
			if j == 0:
				dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + a[i + 1])
				if i < n - 2:
					dp[i + 2][1] = min(dp[i + 2][1], dp[i][0] + a[i + 1] + a[i + 2])
			else:
				dp[i + 1][0] = min(dp[i + 1][0], dp[i][1])
				if i < n - 2:
					dp[i + 2][0] = min(dp[i + 2][0], dp[i][1])
	ans = min(dp[-1][0], dp[-1][1])
	print(ans)


import sys

def I():
	return int(sys.stdin.readline().rstrip())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
t = I()
for _ in range(t):
	n = I()
	A = LI()
	ans = 0
	if A[0] == 1:
		ans += 1
	count = 0
	for i in range(1, n):
		if A[i] == 1:
			count += 1
		else:
			ans += count // 3
			count = 0
	ans += count // 3
	print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dp_me = [0] * n
	dp_friend = [0] * n
	dp_friend[n - 1] = 1 if arr[n - 1] == 1 else 0
	dp_friend[n - 2] = 1 if arr[n - 2] == 1 else 0
	for j in range(n - 3, -1, -1):
		dp_me[j] = min(dp_friend[j + 1], dp_friend[j + 2])
		dp_friend[j] = min(arr[j] + dp_me[j + 1], arr[j] + arr[j + 1] + dp_me[j + 2])
	print(dp_friend[0])


tests = int(input())
for test in range(tests):
	n = int(input())
	a = [int(i) for i in input().split()]
	dp = [n + 1] * n + [0, 0, 0, 0]
	dp[n - 1] = a[n - 1]
	for i in range(n - 2, -1, -1):
		(b1, b2) = (0, 0)
		if a[i] == 1:
			b1 = 1
		if a[i + 1] == 1:
			b2 = 1
		dp[i] = min(dp[i], b1 + b2 + min(dp[i + 3], dp[i + 4]))
		dp[i] = min(dp[i], b1 + min(dp[i + 2], dp[i + 3]))
	print(dp[0])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [0] * n
	dp[0] = a[0]
	me = 0
	for i in range(1, n):
		if a[i] and me == 2:
			me = 0
			dp[i] = dp[i - 1] + 1
		elif a[i]:
			me += 1
			dp[i] = dp[i - 1]
		else:
			me = 0
			dp[i] = dp[i - 1]
	print(dp[-1])


INF = 10 ** 9

def solve(a):
	f = [[INF, INF] for _ in range(len(a) + 10)]
	f[0][0] = 0
	for i in range(len(a)):
		f[i + 1][1] = min(f[i + 1][1], f[i][0] + a[i])
		f[i + 1][0] = min(f[i + 1][0], f[i][1])
		if i + 1 < len(a):
			f[i + 2][0] = min(f[i + 2][0], f[i][1])
			if a[i] + a[i + 1] < 2:
				f[i + 2][1] = min(f[i + 2][1], f[i][0] + a[i] + a[i + 1])
	return min(f[len(a)][0], f[len(a)][1])
for _ in range(int(input())):
	_ = input()
	a = [int(t) for t in input().split()]
	print(solve(a))


for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	if a[0] == 1:
		s += 1
	c = 0
	for i in range(1, n):
		if a[i] == 1:
			c += 1
		else:
			s += c // 3
			c = 0
	s += c // 3
	print(s)


def run():
	n = int(input())
	nums = ''.join(input().split())
	ans = 0
	ans += int(nums[0])
	ans += nums[1:].count('111')
	print(ans)
T = 1
if T:
	for i in range(int(input())):
		run()
else:
	run()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	if N == 1:
		return A[0]
	dp = [[0, 0] for i in range(N)]
	dp[0][0] = A[0]
	dp[0][1] = float('inf')
	dp[1][0] = A[0] + A[1]
	dp[1][1] = A[0]
	for i in range(2, N):
		dp[i][0] = min(dp[i - 1][1] + A[i], dp[i - 2][1] + A[i - 1] + A[i])
		dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
	return min(dp[N - 1][0], dp[N - 1][1])
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


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
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')
t = int(input())
while t != 0:
	t -= 1
	skip_points = 0
	z = 0
	n = int(input())
	a = list(map(int, input().split()))
	x = []
	for i in range(0, n - 1):
		if a[i] == a[i + 1]:
			z += 1
		else:
			if a[i] == 1:
				x.append(z + 1)
			z = 0
	if a[n - 1] == 1:
		x.append(z + 1)
	if a[0] == 1:
		skip_points = 1
		x[0] -= 1
	for item in x:
		skip_points += item // 3
	print(skip_points)


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


for testcase in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if n == 1:
		print(int(a[0] == 1))
		continue
	(dp1, dp2) = ([-1] * n, [-1] * n)
	(dp1[n - 1], dp2[n - 1]) = (0, int(a[n - 1] == 1))
	(dp1[n - 2], dp2[n - 2]) = (0, int(a[n - 2] == 1))
	i = n - 3
	while i >= 0:
		dp1[i] = min(dp2[i + 1], dp2[i + 2])
		dp2[i] = min(int(a[i] == 1) + dp1[i + 1], int(a[i] == 1) + int(a[i + 1] == 1) + dp1[i + 2])
		i = i - 1
	print(dp2[0])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 1
	o = []
	while i < len(l):
		if l[i] == 1:
			cnt = 0
			j = i
			while j < len(l) and l[j] == 1:
				cnt = cnt + 1
				j = j + 1
			if j == len(l):
				o.append(cnt)
				break
			else:
				o.append(cnt)
				i = j
				f = 0
		else:
			i = i + 1
	ans = 0
	if l[0] == 1:
		ans += 1
	for i in o:
		ans += i // 3
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	temp = 0
	if l[0] == 1:
		ans += 1
	for i in range(1, n):
		if l[i] == 1:
			temp += 1
		else:
			ans += temp // 3
			temp = 0
	ans += temp // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 0
	i = 0
	tn = 1
	while i < n:
		if a[i] == 1:
			s += 1
		if i + 1 < n and a[i + 1] == 0:
			i += 1
		elif i + 2 < n and a[i + 2] == 1:
			i += 3
		else:
			i += 2
	print(s)


for i in range(int(input())):
	x = int(input())
	a = [int(x) for x in input().split()]
	count = 0
	l = 0
	if a[0] == 1:
		count = 1
		a = a[1:]
	k = '0'
	for i in a:
		k = k + str(i)
	k = k[1:]
	print(k.count('111') + count)


from sys import stdin, stdout
dp = [[-1, -1] for i in range(2 * 10 ** 5)]

def query(n, p):
	if dp[n][p] != -1:
		return dp[n][p]
	else:
		best = min(query[n - 1][1 - p], query[n - 1][1 - p])

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		a = [int(i) for i in stdin.readline().split()]
		dp = [[2 * n, 2 * n] for i in range(n + 1)]
		dp[0][1] = 0
		if n == 1:
			print(a[0])
			continue
		for i in range(1, n + 1):
			if i >= 2:
				p = 1
				dp[i][p] = min(dp[i - 1][1 - p], dp[i - 2][1 - p])
				p = 0
				val1 = dp[i - 1][1 - p] + a[i - 1]
				val2 = dp[i - 2][1 - p] + a[i - 1] + a[i - 2]
				dp[i][p] = min(val1, val2)
			else:
				p = 1
				dp[i][p] = dp[i - 1][1 - p]
				p = 0
				val1 = dp[i - 1][1 - p] + a[i - 1]
				dp[i][p] = val1
		print(min(dp[n]))
main()


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = [1, 1] + list(map(int, input().split()))
	ones = []
	cs = 0
	for i in s:
		if i == 1:
			cs += 1
		elif cs:
			ones += (cs,)
			cs = 0
	if cs:
		ones += (cs,)
	ans = 0
	for i in ones:
		ans += i // 3
	print(ans)


def dp_solve(a):
	memo = {}
	n = len(a)

	def solve(r, p):
		if (r, p) in memo.keys():
			return memo[r, p]
		elif r >= n - 2:
			return p * a[r]
		else:
			m = min(p * a[r] + solve(r + 1, 1 - p), p * (a[r] + a[r + 1]) + solve(r + 2, 1 - p))
			memo[r, p] = m
			return m
	for i in range(n - 1, -1, -1):
		for j in range(1):
			solve(i, j)
	return solve(0, 1)
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	print(dp_solve(a))


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

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

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

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Comb:

	def __init__(self, n, mo=10 ** 9 + 7):
		self.fac = [0] * (n + 1)
		self.inv = [1] * (n + 1)
		self.fac[0] = 1
		self.fact(n)
		for i in range(1, n + 1):
			self.fac[i] = i * self.fac[i - 1] % mo
			self.inv[n] *= i
			self.inv[n] %= mo
		self.inv[n] = pow(self.inv[n], mo - 2, mo)
		for i in range(1, n):
			self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo
		return

	def fact(self, n):
		return self.fac[n]

	def invf(self, n):
		return self.inv[n]

	def comb(self, x, y):
		if y < 0 or y > x:
			return 0
		return self.fac[x] * self.inv[x - y] * self.inv[y] % mo
show_flg = False
show_flg = True
ans = 0

def solve_A(x, y, k):
	a = (k * y + k - 1 + x - 2) // (x - 1)
	return a + k
for _ in range(I()):
	ans = 0
	n = I()
	a = LI()
	dp = [[inf] * (n + 1) for i in range(4)]
	dp[3][0] = 0
	for i in range(n):
		dp[0][i + 1] = min(dp[0][i + 1], dp[2][i] + (a[i] == 1), dp[3][i] + (a[i] == 1))
		dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + (a[i] == 1))
		dp[2][i + 1] = min(dp[2][i + 1], dp[0][i], dp[1][i])
		dp[3][i + 1] = min(dp[3][i + 1], dp[2][i])
	ans = min((dp[x][n] for x in range(4)))
	print(ans)


t = int(input(''))
arr = []
for i in range(t):
	input('')
	arr.append(list(map(int, input().split())))
for i in arr:
	n = len(i)
	dp = [0] * (n + 5)
	for j in range(n - 1, -1, -1):
		dp[j] = i[j] + min(dp[j + 2], dp[j + 3])
		if j < n - 1:
			dp[j] = min(dp[j], i[j] + i[j + 1] + min(dp[j + 3], dp[j + 4]))
	print(dp[0])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	ct = a[0]
	prev = -1
	for i in range(1, n):
		if a[i] == 1:
			if prev == 1:
				ct += 1
				prev = -1
			else:
				prev += 1
		else:
			prev = -1
	print(ct)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 99999999999999999999999999999999

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = ria()
		if n < 3:
			print(a[0])
		else:
			dp = [[0, 0] for i in range(n)]
			dp[0][0] = a[0]
			dp[0][1] = INF
			dp[1][0] = a[0] + a[1]
			dp[1][1] = a[0]
			for i in range(2, n):
				dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1])
				dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
			wi(min(dp[n - 1][0], dp[n - 1][1]))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	if n == 1:
		print(arr[0])
	else:
		dp = [[0, 0] for i in range(n)]
		dp[-1] = [arr[-1], 0]
		dp[-2] = [arr[-2], 0]
		for k in range(n - 3, -1, -1):
			dp[k][0] = arr[k] + dp[k + 1][1]
			if arr[k] + arr[k + 1] + dp[k + 2][1] < dp[k][0]:
				dp[k][0] = arr[k] + arr[k + 1] + dp[k + 2][1]
			dp[k][1] = min(dp[k + 1][0], dp[k + 2][0])
		print(dp[0][0])


import collections
for t in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))[::-1]
	temp = []
	pre = num.pop()
	count = 1
	while num:
		val = num.pop()
		if val == pre:
			count += 1
		else:
			if pre == 1:
				temp.append(count)
				pre = 0
			else:
				temp.append(-count)
				pre = 1
			count = 1
	if pre == 1:
		temp.append(count)
	else:
		temp.append(-count)
	status = 0
	out = 0
	for i in temp:
		if i > 0:
			val = i
			if status == 1:
				val = max(0, i - 2)
			while val > 0:
				out += 1
				val -= 1
				status = 1
				if val == 0:
					break
				val = max(0, val - 2)
				status = 0
		else:
			status = 1
	print(out)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def solve2():
	A = [1]
	dp = {}

	def check_recur(idx, person, last_done):
		if idx > len(A) - 1:
			return 0
		total = 0
		t = 1 if person and A[idx] else 0
		if last_done <= 1:
			total = t + check_recur(idx + 1, person ^ 1, (last_done + 1) % 2)
		if idx < len(A) - 1:
			t += 1 if person and A[idx + 1] else 0
			total = min(total, check_recur(idx + 2, person ^ 1, 0) + t)
		print(idx, total)
		return total
	print(check_recur(0, 1, 0))

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		dp = [[float('inf')] * 2 for x in range(len(A) + 1)]
		dp[0][1] = 0
		for i in range(len(A)):
			for player in range(2):
				for k in range(1, min(2, len(A) - i) + 1):
					hard_players = A[i] + (A[i + 1] if k > 1 and k < len(A) else 0)
					dp[i + k][player ^ 1] = min(dp[i + k][player ^ 1], dp[i][player] + player * hard_players)
		cout << min(dp[len(A)][0], dp[len(A)][1]) << endl

def main():
	solve()
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dp = []
	for i in range(2):
		dp.append([0] * (n + 2))
	dp[0][2] = arr[0]
	if n >= 2:
		dp[0][3] = arr[0] + arr[1]
		dp[1][3] = dp[0][2]
	if n >= 3:
		dp[0][4] = dp[1][3] + arr[2]
		dp[1][4] = min(dp[0][2], dp[0][3])
	for i in range(5, n + 2):
		dp[0][i] = min(dp[1][i - 1] + arr[i - 2], dp[1][i - 2] + arr[i - 2] + arr[i - 3])
		dp[1][i] = min(dp[0][i - 1], dp[0][i - 2])
	if n == 1:
		print(dp[0][n + 1])
	else:
		print(min(dp[0][n + 1], dp[1][n + 1]))


def solver():
	n = int(input())
	bosses = list(map(int, input().split()))
	(skips, i) = (0, 1)
	skips += bosses[0]
	while i < n - 2:
		if bosses[i] == 1 and bosses[i + 1] == 1 and (bosses[i + 2] == 1):
			skips += 1
			i += 3
		else:
			i += 1
	return skips
t = int(input())
for _ in range(t):
	print(solver())


import math
t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	dp = []
	for i in range(n + 1):
		temp = [math.inf] * 2
		dp.append(temp)
	dp[0][1] = 0
	for i in range(n):
		for who in range(2):
			for fight in range(1, min(n - i + 1, 3)):
				hard = li[i] + (li[i + 1] if fight > 1 else 0)
				dp[i + fight][1 - who] = min(dp[i + fight][1 - who], who * hard + dp[i][who])
	print(min(dp[n][0], dp[n][1]))


import sys
import math as mt
import collections as cc
import sys
import itertools as it
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	ar = I()
	dp = [[10 ** 9, 10 ** 9] for i in range(n)]
	for i in range(n):
		if i == 0:
			dp[i][0] = ar[i]
			continue
		else:
			dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + ar[i]
			if i >= 2:
				dp[i][1] = min(dp[i - 1][0], dp[i - 2][0])
			else:
				dp[i][1] = dp[i - 1][0]
	print(min(dp[n - 1]))


import sys
input = sys.stdin.readline
cases = int(input())
for case in range(cases):
	n = int(input())
	a = [int(x) for x in input().split()]
	cnt = 0
	if a[0] == 1:
		cnt += 1
	cur_len = 0
	for i in range(1, n):
		if a[i] == 1:
			cur_len += 1
		else:
			cnt += cur_len // 3
			cur_len = 0
	cnt += cur_len // 3
	print(cnt)


from functools import lru_cache
import sys
readline = sys.stdin.readline
INF = 1 << 60

def read_int():
	return int(readline())

def read_int_n():
	return list(map(int, readline().split()))

def read_float():
	return float(readline())

def read_float_n():
	return list(map(float, readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def ep(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.perf_counter()
		ret = f(*args, **kwargs)
		e = time.perf_counter()
		ep(e - s, 'sec')
		return ret
	return wrap

def slv(N, A):
	A.append(0)
	A.append(0)
	memo = [[INF] * (N + 2) for _ in range(2)]
	memo[0][0] = 0
	for i in range(N):
		for p in range(2):
			o = p ^ 1
			if p == 0:
				memo[o][i + 1] = min(memo[o][i + 1], memo[p][i] + A[i])
				memo[o][i + 2] = min(memo[o][i + 2], memo[p][i] + A[i] + A[i + 1])
			else:
				memo[o][i + 1] = min(memo[o][i + 1], memo[p][i])
				memo[o][i + 2] = min(memo[o][i + 2], memo[p][i])
	return min(memo[0][N], memo[1][N])

def main():
	for _ in range(read_int()):
		N = read_int()
		A = read_int_n()
		print(slv(N, A))
main()


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

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

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 inp():
	return sys.stdin.readline()

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

def itg():
	return int(sys.stdin.readline())
INF = int(1000000.0)
for __ in range(itg()):
	n = itg()
	if n == 1:
		print(inp())
		continue
	arr = tuple(mpint())
	dp1 = [INF] * n
	dp2 = [INF] * n
	dp1[-1] = arr[-1]
	dp1[-2] = arr[-2]
	dp2[-2] = dp2[-1] = 0
	for i in range(n - 3, -1, -1):
		dp1[i] = min(arr[i] + dp2[i + 1], arr[i] + arr[i + 1] + dp2[i + 2])
		dp2[i] = min(dp1[i + 1], dp1[i + 2])
	print(dp1[0])


from math import inf

def solve(n, a):
	dp = (0, inf, a[0], a[0])
	for i in range(3, n):
		dp = (dp[1], dp[2], dp[3], min(a[i - 3] + a[i - 2] + dp[0], dp[1] + a[i - 2], dp[2] + a[i - 1]))
	if n < 4:
		print(a[0])
	else:
		print(min(dp[3], dp[2] + a[-1], dp[1] + a[-1] + a[-2]))
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	solve(n, a)


t = int(input())
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	num = 10 ** 6
	ar = [[num] * n for i in range(2)]
	ar[0][0] = ai[0]
	if n > 1:
		ar[0][1] = ai[0] + ai[1]
	for i in range(1, n):
		ar[0][i] = min(ar[0][i], ar[1][i - 1] + ai[i])
		ar[1][i] = min(ar[1][i], ar[0][i - 1])
		if i < n - 1:
			ar[0][i + 1] = min(ar[0][i + 1], ar[1][i - 1] + ai[i] + ai[i + 1])
			ar[1][i + 1] = min(ar[1][i + 1], ar[0][i - 1])
	print(min(ar[0][-1], ar[1][-1]))


t = int(input())
res = []
for i in range(t):
	n = int(input())
	a = input()
	conta = a[1:].count('1 1 1')
	antes = '1 1 ' + a[0]
	c = 0
	if antes == '1 1 1':
		c = 1
	res.append(c + conta)
for j in res:
	print(j)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	session = 1
	killed = 0
	skips = 0
	i = 0
	while i < n:
		if a[i] == '1':
			if session == 1 and killed == 0:
				skips += 1
				if i < n - 1 and a[i + 1] == '0':
					if i < n - 3 and a[i + 2] == '0' and (a[i + 3] == '1'):
						session = 0
					else:
						killed += 1
				else:
					session = 0
			elif session == 0:
				killed += 1
				if i < n - 3 and a[i + 1] == '0' and (a[i + 2] == '0') and (a[i + 3] == '1'):
					session = 1
					killed = 0
				elif killed > 2:
					session = 1
					killed = 0
				else:
					killed += 1
		elif a[i] == '0':
			killed += 1
			if session == 0 and i < n - 2 and (a[i + 1] == '0') and (a[i + 2] == '1'):
				session = 1
				killed = 0
			elif i < n - 1 and a[i + 1] == '1':
				session = 0
				killed = 0
			elif killed > 2:
				session = 1 - session
				killed = 0
		i += 1
	print(skips)


T = int(input())
for t in range(T):
	N = int(input())
	arr = [int(i) for i in input().split()]
	INF = 10 ** 9
	DP = [[INF] * 2 for i in range(N)]
	DP[0][0] = arr[0]
	if N > 1:
		DP[1][0] = arr[1] + arr[0]
	for i in range(1, N):
		DP[i][1] = min(DP[i][1], DP[i - 1][0])
		DP[i][0] = min(DP[i][0], DP[i - 1][1] + arr[i])
		if i + 1 < N:
			DP[i + 1][1] = min(DP[i + 1][1], DP[i - 1][0])
			DP[i + 1][0] = min(DP[i + 1][0], DP[i - 1][1] + arr[i] + arr[i + 1])
	print(min(DP[N - 1][0], DP[N - 1][1]))


for test in range(int(input())):
	pocet = int(input())
	a = list(map(int, input().split(' ')))
	k = 0
	if a[0] == 1:
		k += 1
	a.remove(a[0])
	ind1_kon = 0
	este = len(a) > 0
	while este:
		try:
			ind1_zac = a.index(1, ind1_kon)
		except:
			este = False
		if este:
			try:
				ind1_kon = a.index(0, ind1_zac)
			except:
				ind1_kon = len(a)
				este = False
			skip = (ind1_kon - ind1_zac) // 3
			k += skip
	print(k)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.append(0)
	dp = [0] * (n + 4)
	for i in range(n - 1, -1, -1):
		dp[i] += l[i] + min(dp[i + 4] + l[i + 1], dp[i + 3], dp[i + 2])
	print(dp[0])


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')
from collections import deque
for j in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	pos = []
	for s in range(n):
		if vals[s] == 1:
			pos.append(s)
	pos = deque(pos)
	ind = 0
	cv = 0
	cost = 0
	while ind < n and len(pos) > 0:
		if cv % 2 == 0:
			if ind == pos[0]:
				pos.popleft()
				cost += 1
				ind += 1
				if len(pos) > 0 and (ind + 2 < pos[0] or ind + 1 == pos[0]):
					ind += 1
			elif ind + 2 == pos[0]:
				ind += 2
			else:
				ind += 1
		elif ind == pos[0]:
			pos.popleft()
			ind += 1
			if len(pos) > 0 and ind == pos[0]:
				pos.popleft()
				ind += 1
		elif ind + 1 == pos[0]:
			ind += 2
			pos.popleft()
		else:
			ind += 1
		cv += 1
	print(cost)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	s = a[0]
	i = 1
	while i < n - 2:
		if a[i] + a[i + 1] + a[i + 2] == 3:
			s += 1
			i += 2
		i += 1
	print(s)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, values) = (int(input()), [int(i) for i in input().split()] + [0])
	dp = [[float('inf'), float('inf')] for i in range(n + 1)]
	dp[0][1] = 0
	for i in range(n):
		for j in range(2):
			for k in range(1, min(n - i, 2) + 1):
				new = values[i] + values[i + 1] * (k - 1)
				dp[i + k][(j + 1) % 2] = min(dp[i + k][(j + 1) % 2], dp[i][j] + j * new)
	print(min(dp[n][0], dp[n][1]))


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	n = I()
	l = L()
	i = ans = 0
	f = 1
	while i < n:
		if l[i] == 1:
			j = i + 1
			while j < n and l[j] == 0:
				j += 1
			c = j - i - 1
			if f == 1:
				ans += 1
				f = 0
				i = j
			elif c == 0:
				i += 2
				f = 1
			else:
				i = j
		else:
			j = i + 1
			while j < n and l[j] == 0:
				j += 1
			c = j - i
			if f == 1:
				f = 0
				i = j
			elif c == 1:
				i += 2
				f = 1
			else:
				i = j
	print(ans)


from sys import maxsize
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	dp = [[maxsize, maxsize] for i in range(n + 1)]
	dp[n] = [0, 0]
	dp[n - 1][0] = 0
	dp[n - 1][1] = ls[n - 1]
	for i in range(n - 2, -1, -1):
		mn = maxsize
		dp[i][0] = min(dp[i + 1][1], dp[i + 2][1])
		dp[i][1] = min(dp[i + 1][0], dp[i + 2][0] + ls[i + 1]) + ls[i]
	print(dp[0][1])


def recurr(r=0):
	if d[r] != -1:
		return d[r]
	d[r] = min(l[r] + recurr(r + 2), l[r] + recurr(r + 3), l[r] + l[r + 1] + recurr(r + 3), l[r] + l[r + 1] + recurr(r + 4))
	return d[r]
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
		continue
	elif n == 2:
		print(l[0])
		continue
	elif n == 3:
		print(l[0])
		continue
	d = [-1] * n
	d[-1] = l[-1]
	d[-2] = l[-2]
	d[-3] = l[-3]
	d[-4] = min(l[-4] + l[-3], l[-4] + l[-2], l[-4] + l[-1])
	for i in range(n - 5, -1, -1):
		recurr(i)
	print(d[0])


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		if n == 1:
			print(sum(a))
			continue
		dp = [[10 ** 6] * 2 for i in range(n)]
		dp[0][0] = a[0] == 1
		dp[1][0] = (a[0] == 1) + (a[1] == 1)
		for i in range(n - 1):
			for j in range(2):
				skips = 0
				p2 = (j + 1) % 2
				for kills in range(1, 3):
					if i + kills >= n:
						break
					skips += a[i + kills] * (p2 == 0)
					dp[i + kills][p2] = min(dp[i + kills][p2], skips + dp[i][j])
		print(min(dp[n - 1][0], dp[n - 1][1]))
prog()


from math import inf
from collections import defaultdict

def main():
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		a = ''.join(list(map(str, input().split())))
		if a[0] == '1':
			ans += 1
		a = a[1:].split('0')
		for v in a:
			if v:
				ans += v.count('1') // 3
		print(ans)
main()


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [n] * n
	flag = [1] * n
	flag[0] = 1
	if a[0] == 1:
		dp[0] = 1
	else:
		dp[0] = 0
	turn = 0
	for j in range(1, n):
		flag[j] = 1 - flag[j - 1]
		if a[j] == 1:
			dp[j] = dp[j - 1] + flag[j]
			if turn == 0 and dp[j - 1] + flag[j - 1] < dp[j]:
				dp[j] = dp[j - 1] + flag[j - 1]
				flag[j] = flag[j - 1]
				turn = 1
			else:
				turn = 0
		else:
			dp[j] = dp[j - 1]
			if flag[j] == 0:
				turn = 1
				flag[j] = flag[j - 1]
	print(dp[n - 1])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [[float('inf'), float('inf'), float('inf'), float('inf')] for _ in range(n)]
	dp[0][0] = a[0]
	for i in range(1, n):
		for j in range(4):
			if j == 0:
				dp[i][j] = min(dp[i - 1][2], dp[i - 1][3]) + a[i]
			elif j == 1:
				dp[i][j] = dp[i - 1][0] + a[i]
			elif j == 2:
				dp[i][j] = min(dp[i - 1][0], dp[i - 1][1])
			else:
				dp[i][j] = dp[i - 1][2]
	print(min(dp[-1]))


TC = int(input())
for tc in range(TC):
	N = int(input())
	A = list(map(int, input().split()))
	if N < 4:
		print(A[0])
	else:
		dp = [0 for _ in range(N)]
		dp[0] = A[0]
		dp[1] = dp[0]
		dp[2] = dp[0]
		dp[3] = dp[0] + min(A[1], A[2], A[3])
		for i in range(4, N):
			dp[i] = min(dp[i - 1] + A[i], dp[i - 2] + A[i - 1], dp[i - 3] + A[i - 2], dp[i - 4] + A[i - 3] + A[i - 2])
		print(dp[-1])


import math
t = int(input())
for q in range(t):
	n = int(input())
	ans = 0
	a = [int(x) for x in input().split()]
	listToStr = ''.join([str(x) for x in a])
	a = list(map(len, listToStr.split('0')))
	for i in range(len(a)):
		if i == 0:
			ans += math.ceil(a[i] / 3)
		else:
			ans += a[i] // 3
	print(ans)


for tc in range(int(input())):
	n = int(input())
	arr = '1 1 ' + input()
	skips = arr.count('1 1 1')
	print(skips)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	i = 0
	ans = a[0]
	while i < len(a):
		temp = 0
		for j in range(1, 4):
			if i + j < len(a) and a[i + j] == 0:
				i = i + j
				temp = 1
		if temp == 0:
			if i + 3 < len(a):
				ans += 1
			i += 3
	print(ans)


for _ in range(int(input())):
	N = int(input())
	listaString = list(map(str, input().split()))
	lista = []
	if listaString[0] == '1':
		lista.append(1)
	listaUtil = listaString[1:]
	stringFinal = ''.join(listaUtil)
	calculo = sum(lista) + stringFinal.count('111')
	print(calculo)


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	if n == 1:
		print(lst[0])
		return 0
	dpi = [-1 for i in range(n)]
	dpdrug = [-1 for i in range(n)]
	dpi[n - 1] = 0
	dpdrug[n - 1] = lst[n - 1]
	dpi[n - 2] = 0
	dpdrug[n - 2] = lst[n - 2]
	for i in range(n - 3, -1, -1):
		dpi[i] = min(dpdrug[i + 2], dpdrug[i + 1])
		dpdrug[i] = min(dpi[i + 1] + lst[i], dpi[i + 2] + lst[i] + lst[i + 1])
	print(dpdrug[0])
for i in range(int(input())):
	solve()


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [[-1 for i in range(2)] for j in range(n)]
	if len(arr) == 1:
		if arr[0] == 1:
			print(1)
		else:
			print(0)
	else:
		dp = [[n for i in range(2)] for j in range(n)]
		dp[n - 1][0] = 0
		dp[n - 2][0] = 0
		if arr[n - 1] == 1:
			dp[n - 1][1] = 1
		else:
			dp[n - 1][1] = 0
		if arr[n - 2] == 1:
			dp[n - 2][1] = 1
		else:
			dp[n - 2][1] = 0
		for index in range(n - 3, -1, -1):
			dp[index][0] = min(dp[index][0], dp[index + 1][1])
			dp[index][0] = min(dp[index][0], dp[index + 2][1])
			temp = 0
			if arr[index] == 1:
				temp += 1
			dp[index][1] = min(dp[index][1], temp + dp[index + 1][0])
			if arr[index + 1] == 1:
				temp += 1
			dp[index][1] = min(dp[index][1], temp + dp[index + 2][0])
		print(dp[0][1])
	T -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	A.reverse()
	F = [0] * n
	M = [0] * n
	F[0] = A[0]
	if n == 1:
		print(F[0])
		continue
	F[1] = A[1]
	for i in range(2, n):
		M[i] = min(F[i - 1], F[i - 2])
		F[i] = min(A[i] + M[i - 1], A[i] + A[i - 1] + M[i - 2])
	print(F[-1])


q = int(input())
for _ in range(q):
	n = int(input())
	ar = [int(i) for i in input().split()]
	if n == 1:
		print(ar[0])
		continue
	dp = list()
	for ind in range(n + 1):
		dp.append([n + 10, n + 10])
	dp[0][0] = ar[0]
	dp[1][0] = ar[0] + ar[1]
	dp[1][1] = dp[0][0]
	for i in range(0, n):
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][1])
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + ar[i])
		if i + 2 <= n:
			dp[i + 2][0] = min(dp[i + 2][0], dp[i][1])
			dp[i + 2][1] = min(dp[i + 2][1], dp[i][0] + ar[i] + ar[i + 1])
	print(min(dp[n][0], dp[n][1]))


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
setrecursionlimit(10 ** 5)
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))
MOD = 10 ** 9 + 7

def main():
	T = int(rl())
	for _ in range(T):
		n = int(rl())
		A = list(rli())
		dp = [[INF for __ in range(2)] for _ in range(n + 1)]
		dp[0][0] = 0
		for i in range(n):
			for p in range(2):
				if p == 0:
					cnt = 1 if A[i] == 1 else 0
					dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + cnt)
					if i < n - 1:
						cnt = cnt + (1 if A[i + 1] == 1 else 0)
						dp[i + 2][1] = min(dp[i + 2][1], dp[i][0] + cnt)
				else:
					dp[i + 1][0] = min(dp[i + 1][0], dp[i][1])
					if i < n - 1:
						dp[i + 2][0] = min(dp[i + 2][0], dp[i][1])
		ans = min(dp[n][0], dp[n][1])
		print(ans)
	stdout.close()
main()


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def I():
	return int(sys.stdin.readline())

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
from functools import lru_cache
for _ in range(I()):
	N = I()
	A = Neo()
	if N == 1:
		print(A[0])
	else:
		dp = [[0, 0] for i in range(N)]
		dp[-1] = [A[-1], 0]
		dp[-2] = [A[-2], 0]
		for i in range(N - 3, -1, -1):
			dp[i][0] = min(A[i] + dp[i + 1][1], A[i] + A[i + 1] + dp[i + 2][1])
			dp[i][1] = min(dp[i + 1][0], dp[i + 2][0])
		print(dp[0][0])


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 30
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')

def binary_search(data, val, le):
	test = le
	if val >= data[-1]:
		return [test - 1, test - 1]
	elif val <= data[0]:
		return [0, 0]
	high_index = test - 1
	low_index = 0
	while high_index > low_index:
		index = (high_index + low_index) // 2
		sub = data[index]
		if data[low_index] == val:
			return [low_index, low_index]
		elif sub == val:
			return [index, index]
		elif data[high_index] == val:
			return [high_index, high_index]
		elif sub > val:
			if high_index == index:
				return sorted([high_index, low_index])
			high_index = index
		else:
			if low_index == index:
				return sorted([high_index, low_index])
			low_index = index
	return sorted([high_index, low_index])
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	z = l[0]
	i = 1
	while i < n - 2:
		if l[i] == 1 and l[i + 1] == 1 and (l[i + 2] == 1):
			z += 1
			i += 3
		else:
			i += 1
	print(z)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	i = 1
	if a[0] == 1:
		ans += 1
	while i < n:
		if a[i]:
			count = 1
			while i + 1 < n and a[i + 1]:
				count += 1
				i += 1
			ans += count // 3
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [[0 for p in range(2)] for i in range(n + 1)]
	for i in range(n, -1, -1):
		for p in range(2):
			if i == n:
				dp[i][p] = 0
			elif p == 0:
				cands = []
				if i + 1 <= n:
					cands.append(arr[i] + dp[i + 1][(p + 1) % 2])
				if i + 2 <= n:
					cands.append(arr[i] + arr[i + 1] + dp[i + 2][(p + 1) % 2])
				dp[i][p] = min(cands)
			elif p == 1:
				cands = [dp[j][(p + 1) % 2] for j in (i + 1, i + 2) if j <= n]
				dp[i][p] = min(cands)
	result = dp[0][0]
	print(result)


import sys
from collections import defaultdict
input = sys.stdin.readline
from collections import deque

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
nb = inp()
for i in range(nb):
	count = 0
	n = inp()
	tab = inlt()
	res = 0
	for j in range(n):
		count = count % 4
		if count % 4 == 0:
			if tab[j] == 1:
				res += 1
				count += 1
			else:
				count += 1
			continue
		if count % 4 == 1:
			if tab[j] == 1:
				count += 2
			elif tab[(j + 1) % (n - 1)] == 0:
				count += 2
			else:
				count += 1
			continue
		if count % 4 == 2:
			count = count + 1
			continue
		if count % 4 == 3:
			if tab[j] == 1:
				count += 1
			else:
				count += 2
			continue
	print(res)


t = int(input())
for t_ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if len(a) <= 3:
		print(a[0])
	else:
		s = {}
		ns = {}
		s['00'] = 10
		s['01'] = 10
		s['10'] = a[0]
		s['11'] = a[0] + a[1]
		for i in range(2, n):
			ns['00'] = s['10']
			ns['11'] = s['01'] + a[i]
			ns['01'] = min(s['00'] + a[i], s['10'] + a[i])
			ns['10'] = min(s['01'], s['11'])
			(s['00'], s['01'], s['10'], s['11']) = (ns['00'], ns['01'], ns['10'], ns['11'])
		print(min(s['00'], s['01'], s['10'], s['11']))


def FriendTurn():
	global point, n, pos
	if a[pos] == 1:
		point += 1
		pos += 1
	else:
		pos += 1
	if pos + 1 < n and a[pos + 1] == 0:
		return
	elif pos < n and a[pos] == 0:
		pos = pos + 1

def MyTurn():
	global point, n, pos
	if pos + 2 > n:
		pos = n
		return
	else:
		pos += 1
		if a[pos] == 1:
			pos += 1
c = int(input())
for i in range(c):
	n = int(input())
	a = list(map(int, input().split()))
	point = 0
	pos = 0
	while pos < n:
		FriendTurn()
		MyTurn()
	print(point)


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')

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

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

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

def print_list(l):
	print(' '.join(map(str, l)))
from collections import defaultdict as dc
for _ in range(N()):
	n = N()
	a = RLL()
	dp = [0] * n
	dp[0] = a[0]
	if n > 1:
		dp[1] = a[0] + a[1]
	if n > 2:
		dp[2] = dp[0] + a[2]
	if n > 3:
		dp[3] = a[3] + dp[0]
	for i in range(4, n):
		dp[i] = min(a[i] + a[i - 1] + dp[i - 4], a[i] + dp[i - 3], a[i] + dp[i - 2])
	if n < 4:
		print(dp[0])
	else:
		print(min(dp[-3:]))


t = int(input())
for x in range(t):
	s = input()
	s = input()
	s1 = s.split()
	l = [int(i) for i in s1]
	dp = [[100000000.0 for i in range(2)] for j in range(len(l) + 1)]
	dp[0][1] = 0
	for i in range(0, len(l) + 1):
		for j in range(2):
			for k in range(1, 3):
				if i + k < len(dp):
					if j == 0:
						dp[i + k][1 - j] = min(dp[i + k][1 - j], dp[i][j])
					elif j == 1:
						if k == 1:
							dp[i + k][1 - j] = min(dp[i + k][1 - j], dp[i][j] + l[i + k - 1])
						if k == 2:
							dp[i + k][1 - j] = min(dp[i + k][1 - j], dp[i][j] + l[i + k - 1] + l[i + k - 2])
	print(min(dp[len(l)][1], dp[len(l)][0]))


for sfs in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [n + 10 for i in range(n + 1)]
	dp[0] = 0
	for i in range(n - 1):
		dp[i + 2] = min(dp[i + 2], dp[i] + a[i])
		if i < n - 2:
			dp[i + 3] = min(dp[i + 3], dp[i] + a[i])
			if i < n - 3:
				dp[i + 4] = min(dp[i + 4], dp[i] + a[i] + a[i + 1])
	dp[n] = min(dp[n], dp[n - 1] + a[n - 1])
	print(dp[n])


t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	i = 0
	f = 1
	count = 0
	while i < len(list1):
		if f == 1:
			if list1[i] == 1:
				i += 1
				count += 1
			if i < len(list1) and list1[i] == 1:
				f = 0
			elif i < len(list1) and list1[i] == 0:
				while i < len(list1) and list1[i] == 0:
					i += 1
				f = 0
		else:
			if list1[i] == 1:
				i += 1
			if i < len(list1) and list1[i] == 0:
				f = 1
			elif i < len(list1) and list1[i] == 1:
				i += 1
				f = 1
	print(count)
	t -= 1


t = int(input())

def skips_used(arr):
	count = 0
	for i in arr:
		if i == 1:
			count += 1
	return count
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	dp = [0] * (n + 4)
	for i in range(n - 1, -1, -1):
		option1 = skips_used(arr[i:i + 1]) + dp[i + 2]
		option2 = skips_used(arr[i:i + 2]) + dp[i + 3]
		option3 = skips_used(arr[i:i + 1]) + dp[i + 3]
		option4 = skips_used(arr[i:i + 2]) + dp[i + 4]
		dp[i] = min(option1, option2, option3, option4)
	print(dp[0])


import heapq
import collections
from math import log2
import itertools
from functools import lru_cache
from sys import setrecursionlimit as srl
srl(2 * 10 ** 6)
N = 200001

def solve(n, a):
	friend = [0] * (n + 1)
	my = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		friend[i] = my[i + 1] + a[i]
		if i + 2 <= n:
			friend[i] = min(friend[i], my[i + 2] + a[i] + a[i + 1])
		my[i] = friend[i + 1]
		if i + 2 <= n:
			my[i] = min(my[i], friend[i + 2])
	return friend[0]
t = int(input())
for _ in range(1, t + 1):
	n = int(input())
	a = []
	in_ = map(int, input().split())
	for x in in_:
		a.append(x)
	print(solve(n, a))


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 100000007
INF = float('inf')
for _ in range(int(input())):
	n = int(input())
	dp = [[INF] * (n + 1) for i in range(2)]
	boses = [int(i) for i in input().split()]
	dp[1][1] = boses[0]
	dp[0][0] = 0
	for i in range(2, n + 1):
		dp[0][i] = min(dp[1][i - 1], dp[1][i - 2])
		dp[1][i] = min(dp[0][i - 1], dp[0][i - 2] + boses[i - 2]) + boses[i - 1]
	print(min(dp[0][n], dp[1][n]))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	if n == 1:
		print(*arr)
		continue
	dp = [[0 for i in range(4)] for j in range(n)]
	(dp[0][1], dp[0][2], dp[0][3]) = (9999, 9999, 9999)
	dp[0][0] = arr[0]
	if arr[1] == 1:
		dp[1][0] = 9999
		dp[1][1] = dp[0][0] + 1
		dp[1][2] = dp[0][0]
		dp[1][3] = 9999
	else:
		dp[1][0] = 9999
		dp[1][1] = dp[0][0]
		dp[1][2] = dp[0][0]
		dp[1][3] = 9999
	for i in range(2, n):
		if arr[i] == 0:
			dp[i][0] = min(dp[i - 1][2], dp[i - 1][3])
			dp[i][1] = dp[i - 1][0]
			dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])
			dp[i][3] = dp[i - 1][2]
		else:
			dp[i][0] = min(dp[i - 1][2], dp[i - 1][3]) + 1
			dp[i][1] = dp[i - 1][0] + 1
			dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])
			dp[i][3] = dp[i - 1][2]
	print(min(dp[-1]))


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	if n == 1:
		if a[0] == 0:
			P(0)
			return
		else:
			P(1)
			return
	dp = [[[10000000.0 for k in range(2)] for j in range(2)] for i in range(n)]
	if a[0] == 0:
		dp[0][0][0] = 0
		if a[1] == 0:
			dp[0][0][1] = 0
		else:
			dp[0][0][1] = 1
	else:
		dp[0][0][0] = 1
		if a[1] == 0:
			dp[0][0][1] = 1
		else:
			dp[0][0][1] = 2
	for i in range(1, n):
		if a[i] == 0:
			dp[i][0][0] = min(dp[i - 1][1][0], dp[max(i - 2, 0)][1][0 if i - 2 < 0 else 1])
			dp[i][1][0] = min(dp[i - 1][0][0], dp[max(i - 2, 0)][0][0 if i - 2 < 0 else 1])
			if i + 1 < n:
				if a[i + 1] == 0:
					dp[i][0][1] = min(dp[i - 1][1][0], dp[max(i - 2, 0)][1][0 if i - 2 < 0 else 1])
					dp[i][1][1] = min(dp[i - 1][0][0], dp[max(i - 2, 0)][0][0 if i - 2 < 0 else 1])
				else:
					dp[i][0][1] = min(dp[i - 1][1][0], dp[max(i - 2, 0)][1][0 if i - 2 < 0 else 1]) + 1
					dp[i][1][1] = min(dp[i - 1][0][0], dp[max(i - 2, 0)][0][0 if i - 2 < 0 else 1])
		else:
			dp[i][0][0] = min(dp[i - 1][1][0], dp[max(i - 2, 0)][1][0 if i - 2 < 0 else 1]) + 1
			dp[i][1][0] = min(dp[i - 1][0][0], dp[max(i - 2, 0)][0][0 if i - 2 < 0 else 1])
			if i + 1 < n:
				if a[i + 1] == 0:
					dp[i][0][1] = min(dp[i - 1][1][0], dp[max(i - 2, 0)][1][0 if i - 2 < 0 else 1]) + 1
					dp[i][1][1] = min(dp[i - 1][0][0], dp[max(i - 2, 0)][0][0 if i - 2 < 0 else 1])
				else:
					dp[i][0][1] = min(dp[i - 1][1][0], dp[max(i - 2, 0)][1][0 if i - 2 < 0 else 1]) + 2
					dp[i][1][1] = min(dp[i - 1][0][0], dp[max(i - 2, 0)][0][0 if i - 2 < 0 else 1])
	P(min(dp[n - 1][0][0], dp[n - 1][1][0], dp[n - 2][0][1], dp[n - 2][1][1]))
	return
t = II()
for i in range(t):
	solve()


from sys import stdin, stdout

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

def gms():
	return map(str, stdin.readline().strip().split())

def gari():
	return list(map(int, stdin.readline().strip().split()))

def gars():
	return list(map(int, stdin.readline().strip().split()))

def gs():
	return stdin.readline().strip()

def gls():
	return list(stdin.readline())

def gi():
	return int(stdin.readline())
from math import ceil, floor
t = gi()
while t:
	t -= 1
	n = gi()
	ar = gari()
	ch = True
	r = 0
	i = 0
	ans = 0
	while i < n:
		if ch:
			if ar[i] == 0:
				r += 1
				i += 1
			elif r == 0:
				r += 1
				i += 1
				ans += 1
			else:
				r = 0
				ch = not ch
		elif ar[i]:
			i += 1
			r += 1
		else:
			r = 0
			ch = not ch
		if r == 2:
			r = 0
			ch = not ch
	print(ans)