You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.

However, the site is not so simple on the inside. There are two servers, each with its separate counts for the upvotes and the downvotes.

$n$ reviewers enter the site one by one. Each reviewer is one of the following types:

type $1$: a reviewer has watched the movie, and they like it — they press the upvote button;

type $2$: a reviewer has watched the movie, and they dislike it — they press the downvote button;

type $3$: a reviewer hasn't watched the movie — they look at the current number of upvotes and downvotes of the movie on the server they are in and decide what button to press. If there are more downvotes than upvotes, then a reviewer downvotes the movie. Otherwise, they upvote the movie.

Each reviewer votes on the movie exactly once.

Since you have two servers, you can actually manipulate the votes so that your movie gets as many upvotes as possible. When a reviewer enters a site, you know their type, and you can send them either to the first server or to the second one.

What is the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.

Then the descriptions of $t$ testcases follow.

The first line of each testcase contains a single integer $n$ ($1 \le n \le 50$) — the number of reviewers.

The second line of each testcase contains $n$ integers $r_1, r_2, \dots, r_n$ ($1 \le r_i \le 3$) — the types of the reviewers in the same order they enter the site.


-----Output-----

For each testcase print a single integer — the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to.


-----Examples-----

Input
4
1
2
3
1 2 3
5
1 1 1 1 1
3
3 3 2
Output
0
2
5
2


-----Note-----

In the first testcase of the example you can send the only reviewer to either of the servers — they'll downvote anyway. The movie won't receive any upvotes.

In the second testcase of the example you can send all reviewers to the first server:

the first reviewer upvotes;

the second reviewer downvotes;

the last reviewer sees that the number of downvotes is not greater than the number of upvotes — upvote themselves.

There are two upvotes in total. Alternatevely, you can send the first and the second reviewers to the first server and the last reviewer — to the second server:

the first reviewer upvotes on the first server;

the second reviewer downvotes on the first server;

the last reviewer sees no upvotes or downvotes on the second server — upvote themselves.

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	a = [int(i) for i in input().split()]
	for i in a:
		if i == 1 or i == 3:
			ans += 1
	print(ans)


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	r = a.count(1) + a.count(3)
	print(r)


import math

def solve():
	a = int(input())
	l = [int(i) for i in input().split()]
	one = 0
	uv = 0
	two = 0
	for i in l:
		if i == 1:
			if one > two:
				one += 1
			else:
				two += 1
			uv += 1
		if i == 2:
			if one < two:
				one -= 1
			else:
				two -= 1
		if i == 3:
			if one >= 0:
				one += 1
				uv += 1
			elif two >= 0:
				two += 1
				uv += 1
			elif two < 0 and one < 0:
				if two < one:
					two -= 1
				else:
					one -= 1
	print(uv)

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


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import sys
import copy

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

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

def input():
	return sys.stdin.readline().strip()
ar = [2, 11, 101, 1009, 10009, 100019, 1000033, 10000019, 100000037]
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	print(a.count(1) + a.count(3))


for t in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	up = 0
	down = 0
	for x in r:
		if x == 2:
			down += 1
		else:
			up += 1
	print(up)


n = int(input())
for _ in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	l = []
	l.append(b.count(1) + b.count(3))
	print(*l)


import sys
import math
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)
N = 20005

def getSum(n):
	sum = 0
	for digit in str(n):
		sum += int(digit)
	return sum
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	d = {1: 0, 2: 0, 3: 0}
	for i in range(n):
		d[a[i]] += 1
	print(d[1] + d[3])


import sys
import os
import math
import copy
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations, accumulate

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

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

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Mat2x2(n):
	return [Lstr() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

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

def btod(n):
	return int(n, 2)

def watch(x):
	return print(x)

def common(l1, l2):
	return set(l1).intersection(l2)

def Most_frequent(list):
	return max(set(list), key=list.count)

def solution():
	for _ in range(Int()):
		n = Int()
		a = List()
		u = 0
		d = 0
		for i in range(n):
			if a[i] == 1:
				u += 1
			elif a[i] == 2:
				d += 1
			else:
				u += 1
		print(u)
solution()


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	up = l.count(1)
	down = l.count(2)
	bias = l.count(3)
	print(up + bias)


def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		r = list(map(int, input().split()))
		count = 0
		for i in r:
			if i == 1 or i == 3:
				count += 1
		print(count)
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	print(s.count(1) + s.count(3))


import sys
from collections import Counter
input = sys.stdin.readline
t = int(input().strip())
while t:
	t -= 1
	n = int(input().strip())
	r = list(map(int, input().strip().split()))
	counter = Counter(r)
	print(counter[1] + counter[3])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in a:
		if i == 1 or i == 3:
			ans += 1
	print(ans)


def solN():
	n = int(input())
	r = list(map(int, input().split()))
	u = 0
	for i in r:
		if i == 1 or i == 3:
			u += 1
	print(u)

def main():
	for _ in range(int(input())):
		solN()
main()


m = int(input())
l = []
for i in range(m):
	b = input()
	a = input()
	l.append(a.count('1') + a.count('3'))
for i in l:
	print(i)


t = int(input())
tmp = []
for i in range(t):
	k = int(input())
	a = input().split(' ')
	tmp.append(len(a) - a.count('2'))
for j in tmp:
	print(j)


b = int(input())
listB = []
for k in range(b):
	a = int(input())
	c = list(map(int, input().strip().split()))[:a]
	xx = c.count(2)
	yy = c.count(3) + c.count(1)
	listB.append(yy)
for i in listB:
	print(i)


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


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


def solve():
	k = int(input())
	ans = 0
	inp = list(map(int, input().split()))
	n = len(inp)
	for i in inp:
		if i == 2:
			ans += 1
	ans = k - ans
	return ans
r = []
n = int(input())
for i in range(n):
	re = solve()
	r.append(re)
for i in r:
	print(i)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(l.count(1) + l.count(3))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	ans = r.count(1) + r.count(3)
	print(ans)


T = int(input())
for _ in range(T):
	N = int(input())
	line = input().split(' ')
	print(sum([1 for i in line if i != '2']))


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

def int_in():
	return int(input())
for _ in range(int(input())):
	n = int_in()
	arr = arr_in()
	print(arr.count(3) + arr.count(1))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	reviewer = [int(i) for i in input().strip().split(' ')]
	countLikes = 0
	countDisLikes = 0
	for r in reviewer:
		if r == 1:
			countLikes += 1
		elif r == 2:
			countDisLikes += 1
		else:
			countLikes += 1
	print(f'{countLikes}')


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	count += l.count(1)
	count += l.count(3)
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	r = [int(i) for i in input().split(' ')]
	print(r.count(1) + r.count(3))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	s += l.count(1) + l.count(3)
	print(s)


T = int(input())
for t in range(T):
	n = int(input())
	up = 0
	down = 0
	arr = [int(i) for i in input().split()]
	for i in arr:
		if i != 2:
			up += 1
	print(up)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	r = [int(x) for x in input().split()]
	ans = 0
	for i in range(n):
		ans += r[i] == 1 or r[i] == 3
	print(ans)


for _ in range(0, int(input())):
	input()
	v = input()
	print(v.count('1') + v.count('3'))


for _ in range(int(input())):
	n = int(input())
	down = input().split().count('2')
	print(n - down)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	l = 0
	n = int(input())
	r = map(int, input().split())
	for rr in r:
		if rr == 1 or rr == 3:
			l += 1
	print(l)


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(str, input().split()))
	a = len(r) - r.count('2')
	print(a)


T = int(input())
for t in range(T):
	n = int(input())
	ret = 0
	for r in [int(x) for x in input().split()]:
		if r == 1 or r == 3:
			ret += 1
	print(ret)


t = int(input())
like = 0
dis = 0
for i in range(t):
	n = int(input())
	a = input().split()
	for j in a:
		if j == '1':
			like += 1
		elif j == '2':
			dis += 1
		else:
			like += 1
	print(like)
	(dis, like) = (0, 0)


import os, sys
from io import BytesIO, IOBase
from collections import deque, Counter, defaultdict as dft
from heapq import heappop, heappush
from math import log, sqrt, factorial, cos, tan, sin, radians, log2, ceil, floor
from bisect import bisect, bisect_left, bisect_right
from decimal import *
import sys, threading
from itertools import permutations, combinations
from copy import deepcopy
input = sys.stdin.readline
ii = lambda : int(input())
si = lambda : input().rstrip()
mp = lambda : map(int, input().split())
ms = lambda : map(str, input().strip().split(' '))
ml = lambda : list(mp())
mf = lambda : map(float, input().split())
alphs = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	n = ii()
	arr = ml()
	res = arr.count(1) + arr.count(3)
	print(res)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
tc = 1
tc = ii()
for i in range(tc):
	solve()


def f(s):
	b = []
	for j in s:
		b.append(j)
	return b
p = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	print(n - b.count(2))


n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	c = l.count(1) + l.count(3)
	print(c)


for _ in range(int(input())):
	a = int(input())
	b = list(map(str, input().split()))
	ans = 0
	for _ in b:
		if _ == '1' or _ == '3':
			ans += 1
	print(ans)


from sys import stdin
input = stdin.readline

def solution():
	N = int(input())
	R = list(map(int, input().split()))
	print(sum((r in [1, 3] for r in R)))
T = int(input())
for _ in range(T):
	solution()


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	count = 0
	for i in range(n):
		if arr[i] == 2:
			pass
		else:
			count += 1
	print(count)


import sys
input = sys.stdin.readline
inputLines = sys.stdin.readlines

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

def readStrList():
	return list(map(lambda x: x.strip(), inputLines()))

def indexOf(l: list, elem):
	return l.index(elem) if elem in l else -1

def lastIndexOf(l: list, elem):
	indexes = [idx for (idx, val) in enumerate(l) if val == elem]
	return max(indexes) if len(indexes) > 0 else -1

def distinct(l: list):
	used = set()
	return [x for x in l if x not in used and (used.add(x) or True)]

def solution():
	for _ in range(int(input())):
		n = int(input())
		reviewers = readIntList()
		print(len([x for x in reviewers if x == 1 or x == 3]))
solution()


for i in range(int(input())):
	(n, ans) = (int(input()), 0)
	for i in list(map(int, input().split())):
		if i != 2:
			ans += 1
	print(ans)


try:
	t = int(input())
	while t:
		n = int(input())
		r = list(map(int, input().split()))
		s = [0, 0]
		for i in range(n):
			if r[i] == 1:
				s[0] += 1
			elif r[i] == 2:
				s[1] += 1
			else:
				s[0] += 1
		print(s[0])
		t -= 1
except EOFError:
	pass


t = int(input())

def f(x):
	y = x.split(' ')
	v = 0
	i = 0
	while i < len(y):
		if y[i] == '1' or y[i] == '3':
			v += 1
			i += 1
		else:
			i += 1
	return v
lines = ''
ans = ''
for i in range(2 * t):
	x = input()
	lines += x + '\n'
	if i % 2 != 0:
		ans += str(f(x)) + '\n'
print(ans)


res = ''
for _ in range(int(input())):
	n = int(input())
	viewers = input().split()
	ans = 0
	for viewer in viewers:
		ans += viewer == '1' or viewer == '3'
	res += '%d\n' % ans
print(res)


for s in [*open(0)][2::2]:
	s = s.split()
	cnt = 0
	for i in s:
		if i in ['1', '3']:
			cnt += 1
	print(cnt)


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


t = int(input())
for i in range(t):
	x = int(input())
	y = list(map(int, input().split()))
	j = y.count(1) + y.count(3)
	print(j)


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


t = int(input())
for _ in range(0, t):
	n = int(input())
	r = list(map(int, input().split()))
	print(n - r.count(2))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(n - l.count(2))


trails = int(input())
answer_list = []
for d in range(trails):
	num = input()
	numbers = input().split()
	num_1 = 0
	num_2 = 0
	num_3 = 0
	for s in numbers:
		if s == '1':
			num_1 += 1
		if s == '2':
			num_2 += 1
		if s == '3':
			num_3 += 1
	answer_list.append(num_3 + num_1)
for e in answer_list:
	print(e)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {1: 0, 2: 0, 3: 0}
	for i in l:
		d[i] += 1
	print(d[1] + d[3])


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	ans = arr.count(1) + arr.count(3)
	print(ans)


import sys
input = sys.stdin.readline

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

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

def inpstrlist():
	s = input()
	return list(s[:len(s)])

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

def printlist(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')
t = inp()
for _ in range(t):
	n = inp()
	arr = inplist()
	c = 0
	for i in range(n):
		if arr[i] == 1 or arr[i] == 3:
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	(n, r) = (int(input()), input().split())
	res = n - sum((i == '2' for i in r))
	print(res)


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		one = 0
		two = 0
		three = 0
		for i in l:
			if i == 1:
				one += 1
			if i == 2:
				two += 1
			if i == 3:
				three += 1
		print(one + three)
main()


import sys
input = sys.stdin.buffer.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().decode().rstrip('\n\r')
wrt = sys.stdout.write
fastop = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
op = print
xrange = lambda *args: reversed(range(*args))
cdiv = lambda x, y: -(-x // y)
enum = enumerate
inf = float('inf')
mod = 10 ** 9 + 7
from collections import defaultdict as dd, Counter
from heapq import *
from math import gcd
Testcase = ri()
for testcase in range(Testcase):
	(n,) = rl()
	a = rl()
	print(a.count(1) + a.count(3))


for _ in ' ' * int(input()):
	n = int(input())
	(*r,) = map(int, input().split())
	likes = 0
	for i in range(n):
		if r[i] == 1:
			likes += 1
		elif r[i] == 2:
			pass
		else:
			likes += 1
	print(likes)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	print(str(a.count(1) + a.count(3)))
for _ in range(int(input())):
	solve()


test_cases = int(input())
for i in range(test_cases):
	n = int(input())
	r = list(map(int, input().split(' ')))
	print(r.count(1) + r.count(3))


for i in range(int(input())):
	_ = input()
	k = sum((1 for i in input().split() if i == '1' or i == '3'))
	print(k)


test = int(input())
while test > 0:
	n = int(input())
	upvote = 0
	for i in input().strip().split():
		z = int(i)
		if (z == 1) | (z == 3):
			upvote += 1
	print(upvote)
	test -= 1


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
import functools
from operator import ixor
from decimal import Decimal
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	for i in a:
		if i != 2:
			k += 1
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	print(ar.count(1) + ar.count(3))


n = int(input())
for i in range(n):
	a = int(input())
	i = list(map(int, input().split()))
	print(a - i.count(2))


arr = []
test_cases = int(input(''))
for x in range(test_cases):
	ajaira = input()
	a = []
	a = list(map(int, input().split()))
	arr.append(a)
for y in arr:
	good_server = 0
	bad_server = 0
	for j in y:
		if j == 1:
			good_server += 1
		elif j == 3:
			good_server += 1
		else:
			bad_server += 1
	print(good_server)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())

def solve(n, arr):
	c = 0
	for i in arr:
		if i != 2:
			c += 1
	print(c)
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	solve(n, arr)


for _ in range(int(input())):
	input()
	q = list(map(int, input().split()))
	print(q.count(1) + q.count(3))


t = int(input())
for j in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	s1 = []
	s2 = []
	for i in r:
		if i == 1:
			s1.append('l')
		if i == 2:
			s1.append('d')
		if i == 3:
			if s1.count('l') >= s1.count('d'):
				s1.append('l')
			else:
				s2.append('l')
	print(s1.count('l') + len(s2))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(l, d) = (0, 0)
	for j in a:
		if j == 1:
			l += 1
		elif j == 2:
			d += 1
		else:
			l += 1
	print(l)


t = int(input())
for i in range(t):
	upvotes = 0
	reviewers = int(input())
	data = list(map(int, input().split()))
	upvotes = data.count(1) + data.count(3)
	print(upvotes)


Test = int(input())
for T in range(Test):
	n = int(input())
	Dta = list(map(int, input().split()))
	U1 = D1 = U2 = D2 = 0
	for K in Dta:
		if K == 1:
			U1 += 1
		elif K == 2:
			D2 += 1
		elif U1 >= D1:
			U1 += 1
		else:
			U2 += 1
	print(U1 + U2)


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	ans = 0
	for x in r:
		if x == 1 or x == 3:
			ans += 1
	print(ans)


m = int(input())
while m != 0:
	i = 0
	j = 0
	b = input()
	a = list(map(int, input().split()))
	q1 = a.count(1)
	q2 = a.count(2)
	q3 = a.count(3)
	print(q1 + q3)
	m = m - 1


import math
test = int(input())
for t in range(test):
	n = int(input())
	x = list(map(int, input().split()))
	a = 0
	for i in range(n):
		if x[i] == 1 or x[i] == 3:
			a += 1
	print(a)


T = int(input())

def solve():
	n = int(input())
	types = list(map(int, input().split()))
	server_1 = 0
	server_2 = 0
	for person in types:
		if person in [1, 3]:
			server_1 += 1
	return server_1
for i in range(T):
	ans = solve()
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input().split()
	ans = 0
	for i in a:
		if i != '2':
			ans += 1
	print(ans)


for s in [*open(0)][2::2]:
	print(len(s) // 2 - s.count('2'))


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

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

def check_palindrome(s):
	n = len(s)
	for i in range(n):
		if s[i] != s[n - i - 1]:
			return False
	return True
mod = 10 ** 9 + 7

def check(x, m):
	x = int(x)
	d = {}
	for i in range(11):
		d[i] = 0
	ans = 1
	if 10 - x > m:
		return 1
	d[0] = 1
	m -= 10 - x
	z = m
	ans = 2
	for i in range(10):
		if m == 0:
			break
		y = m // (10 - i)
		ans = (ans + d[i] * y) % mod
		d[i + 1] = y * d[i] % mod
		m -= 1
	if d[10]:
		ans += check(1, m)
		ans += check(0, m)
	for i in range(11):
		d[i] = 0
	ans = ans + check(1, z)
	return ans % mod
for ii in range(int(input())):
	n = int(input())
	arr = arrIn()
	(x, y) = (0, 0)
	for i in range(n):
		if arr[i] == 1:
			x += 1
		elif arr[i] == 2:
			y -= 1
		if arr[i] == 3:
			if x >= 0:
				x += 1
			else:
				y -= 1
	print(x)


(s1, s2) = (0, 0)
tc = int(input())
for _ in range(tc):
	n = int(input())
	li = [int(x) for x in input().split()]
	for x in li:
		if x == 1:
			s1 += 1
		if x == 2:
			s2 += 1
		if x == 3:
			s1 += 1
	print(s1)
	s1 = 0
	s2 = 0


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in a:
		if i != 2:
			ans += 1
	print(ans)


txt = int(input())
for i in range(txt):
	n = int(input())
	a = input()
	print(n - a.count('2'))


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

def case():
	(n,) = ints()
	r = ints()
	return n - r.count(2)
(t,) = ints()
for i in range(t):
	print(case())


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	for i in range(n):
		if arr[i] != 2:
			res += 1
	print(res)
	T -= 1


t = int(input())
l1 = []
l2 = []
r1 = []
count = 0
for x in range(0, t):
	r = int(input())
	l = list(map(str, input().split()))
	l1.append(l)
for x in range(0, t):
	for y in l1[x]:
		if y == '1' or y == '3':
			count += 1
	print(count)
	count = 0


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(a.count(1) + a.count(3))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(up, down, com) = (0, 0, 0)
	for i in a:
		if i == 1:
			up += 1
		elif i == 2:
			down += 1
		else:
			com += 1
	print(up + com)


for _ in range(int(input())):
	n = int(input())
	uv = 0
	for x in input().split():
		if x in '13':
			uv += 1
	print(uv)


T = int(input())
for i in range(T):
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	print(n - l.count(2))


import sys
import bisect
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
gp = []
cost = []
dp = []
mx = []

def dfs(root, par):
	global gp, cost, dp
	dp[root] = cost[root]
	for i in gp[root]:
		if i == par:
			continue
		dfs(i, root)
		dp[root] = max(dp[root], dp[i])

def hnbhai():
	n = sb()
	q = sd()
	s1 = []
	s2 = []
	for i in range(n):
		if q[i] == 2:
			s2.append(q[i])
		else:
			s1.append(q[i])
	print(len(s1))
for _ in range(sb()):
	hnbhai()


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	c = 0
	for i in r:
		if i == 1 or i == 3:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	u = 0
	for i in l:
		if i == 1 or i == 3:
			u = u + 1
	print(u)


cases = int(input())
for i in range(cases):
	votes = 0
	sub = int(input())
	l = [int(x) for x in input().split(' ')]
	for _ in l:
		if _ == 1 or _ == 3:
			votes += 1
	print(votes)


t = int(input())
Sum = 0
for i in range(t):
	n = int(input())
	r = [int(x) for x in input().split()]
	for i in range(len(r)):
		if 1 == r[i] or 3 == r[i]:
			Sum += 1
	print(Sum)
	Sum = 0


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	for i in arr:
		if i == 1 or i == 3:
			res += 1
	print(res)


from io import BytesIO, IOBase
import sys, os
inpl = lambda : list(map(int, input().split()))
inpm = lambda : map(int, input().split())
inpi = lambda : int(input())
inp = lambda : input()
(rev, ra, l) = (reversed, range, len)

class FastIO(IOBase):
	newlines = 0

	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')
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys, operator, math, operator
from collections import Counter
import random
test_Cases = inpi()
while test_Cases:
	test_Cases -= 1
	intn_num = inpi()
	li = list(input())
	answer = li.count('1') + li.count('3')
	print(answer)


for _ in range(int(input())):
	n = int(input())
	a = [int(token) for token in input().split()]
	likes = dislikes = 0
	for i in a:
		if i == 1:
			likes += 1
		elif i == 2:
			dislikes += 1
		else:
			likes += 1
	print(likes)


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	(one, two, a, b, c) = (0, 0, 0, 0, 0)
	two = x.count(2)
	print(len(x) - two)


from sys import stdin

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

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
t = ii()
while t > 0:
	n = ii()
	a = li()
	ans = 0
	for i in a:
		if i != 2:
			ans += 1
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = [0, 0]
	for q in map(int, input().split()):
		if q == 3:
			arr[0] += 1
		else:
			arr[q - 1] += 1
	print(arr[0])


t = int(input())
while t != 0:
	n = int(input())
	arr = [int(k) for k in input().split()]
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if arr[i] == 1:
			cnt1 += 1
		if arr[i] == 2:
			cnt2 += 2
		if arr[i] == 3:
			cnt1 += 1
	print(cnt1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	x_2 = 0
	for i in range(0, n):
		if lst[i] == 1 or lst[i] == 3:
			x_2 += 1
	print(x_2)


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


T = int(input())
for i in range(1, T + 1):
	N = int(input())
	arr = [int(s) for s in input().split()]
	count = 0
	for i in arr:
		if i == 1 or i == 3:
			count += 1
	print(count)


t = int(input().rstrip())
for _ in range(t):
	n = int(input().rstrip())
	list1 = list(map(int, input().rstrip().split(' ')))
	max1 = 0
	count1 = 0
	count2 = 0
	for i in list1:
		if i == 1:
			count1 += 1
			max1 = max([max1, count1])
		elif i == 3:
			count1 += 1
	print(count1)


from collections import Counter
from itertools import permutations

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

def main():
	t = int(input())
	for num in range(t):
		n = int(input())
		arr = getlist()
		count = Counter(arr)
		down = count[2]
		print(n - down)
main()


t = int(input())
p = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	freq = {}
	for item in a:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	b = 0
	c = 0
	d = 0
	for (key, value) in freq.items():
		if key == 1:
			b = value
		elif key == 2:
			c = value
		else:
			d = value
	p.append(b + d)
for i in range(len(p)):
	print(p[i])


t = int(input())
for _ in range(t):
	n = int(input())
	r = map(str, input().split())
	count = 0
	for i in r:
		if i == '1' or i == '3':
			count += 1
	print(count)


import sys, collections, math
sys.setrecursionlimit(1000)

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	arr = input().split()
	print(arr.count('1') + arr.count('3'))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	k = a.count(1) + a.count(3)
	print(k)


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
from bisect import bisect_left, bisect_left
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

def mfloat():
	return map(float, input().split())

def solve():
	n = int(input())
	(*a,) = mint()
	positive = False
	print(a.count(1) + a.count(3))

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


t = int(input())
for i in range(t):
	n = int(input())
	types = list(map(int, input().split()))
	upvotes = types.count(1) + types.count(3)
	print(upvotes)


t = int(input())
for i in range(t):
	b = int(input())
	c = list(map(int, input().split()))
	print(c.count(1) + c.count(3))


for i in range(int(input())):
	n = int(input())
	r = input()
	print(n - r.count('2'))


t = int(input())
for _ in range(t):
	n = int(input())
	type = [int(x) for x in input().split()]
	l = 0
	for x in type:
		if x != 2:
			l += 1
	print(l)


for _ in range(int(input())):
	input()
	ans = 0
	a = input()
	ans += a.count('1')
	ans += a.count('3')
	print(ans)


from time import sleep as sle
from math import *
from random import randint as ri

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		r = [int(q) for q in input().split()]
		print(r.count(1) + r.count(3))
solve()


n = int(input())
for i in range(n):
	t = int(input())
	l = [int(i) for i in input().split()]
	pos = 0
	neg = 0
	for i in l:
		if i == 1:
			pos += 1
		elif i == 2:
			neg -= 1
		elif neg > pos:
			neg -= 1
		else:
			pos += 1
	print(pos)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	c = 0
	for i in arr:
		if i != 2:
			c += 1
	print(c)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(len(arr) - arr.count(2))


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	like = c.count('1')
	dislike = c.count('2')
	pofig = c.count('3')
	print(like + pofig)


import sys
input = sys.stdin.readline
import math

def inpit():
	return int(input())

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

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

def inpspit():
	return map(int, input().split())
import math

def lcm(a):
	return abs(math.prod(a)) // math.gcd(*a)

def func(k, n):
	if k == 1:
		return 1
	return 1 + n + func(k - 1, n)
t = inpit()
for i in range(t):
	n = inpit()
	lt = inplt()
	(a, b, c) = (0, 0, 0)
	for i in lt:
		if i == 1 or i == 3:
			a = a + 1
	print(a)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % 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(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

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

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	r = li()
	up = 0
	f = 0
	for i in range(n):
		if r[i] == 1 or r[i] == 3:
			f = 1
			up += 1
	print(up)
t = 1
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	user_list = list(map(int, input().split()))
	a = 0
	for k in user_list:
		if k == 1 or k == 3:
			a += 1
	print(a)


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


for s in [*open(0)][2::2]:
	l = [*map(int, s.split())]
	print(l.count(1) + l.count(3))


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	a = arr.count(1)
	b = arr.count(3)
	c = a + b
	print(c)
	t = t - 1


from sys import stdin, stdout
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial
for _ in range(it()):
	n = it()
	l = mp()
	u = 0
	for i in range(n):
		if l[i] == 1 or l[i] == 3:
			u += 1
	print(u)


import sys
from math import *
import builtins
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

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

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

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return high

def main():
	p = get_int()
	for q in range(p):
		n = get_int()
		ls = get_list_ints()
		total = 0
		for i in range(n):
			if ls[i] == 1 or ls[i] == 3:
				total += 1
		print(total)
	pass
main()


n = int(input())
v = []
for i in range(n):
	t = int(input())
	l = list(map(int, input().split()))
	z = 0
	for i in l:
		if i == 1 or i == 3:
			z += 1
	v.append(z)
for i in range(n):
	print(v[i])


for i in range(int(input())):
	n = int(input())
	print(n - input().split().count('2'))


t = int(input())
r = []
for i in range(t):
	n = int(input())
	temp = list(map(int, input().split()))
	r.append(temp)

def find_upvote(lst):
	up = 0
	down = 0
	for i in range(len(lst)):
		if lst[i] == 1 or lst[i] == 3:
			up += 1
		else:
			down += 1
	return up
for i in range(t):
	print(find_upvote(r[i]))


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split(' ')))
		ans = a.count(1) + a.count(3)
		print(ans)
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()


for test_index in range(int(input())):
	n = int(input())
	reviewers = input().split()
	count = 0
	for x in reviewers:
		if x != '2':
			count += 1
	print(count)


list1 = []
for i in range(int(input())):
	n = int(input())
	s = input().split()
	list1.append(s.count('1') + s.count('3'))
print(*list1, sep='\n')


n = int(input())
for i in range(n):
	p = int(input())
	a = list(map(int, input().split()))
	print(a.count(1) + a.count(3))


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


t = int(input())
while t:
	n = int(input())
	r = [int(i) for i in input().split()]
	print(r.count(1) + r.count(3))
	t -= 1