Chef lives in a big apartment in Chefland. The apartment charges maintenance fees that he is supposed to pay monthly on time. But Chef is a lazy person and sometimes misses the deadlines. The apartment charges 1000 Rs per month as maintenance fees. Also, they also charge a one-time fine of 100 Rs for each of the late payments. It does not matter how late the payment is done, the fine is fixed to be Rs.100.
Chef has been living in the apartment for N months. Now, he wants to switch the apartment, so he has to pay the entire dues to the apartment. The deadline for the N-th month is also over. From his bank statement, he finds the information whether he paid apartment rent for a particular month for not. You are given this information by an array A of size N, where Ai (can be either 0 or 1) specifies whether he has paid the 1000Rs in the i-th month or not. Assume that Chef paid the fees in the i-th month, then this fees will be considered for the earliest month for which Chef has not yet paid the fees.

For example, assume Chef did not pay any money in first month and 1000Rs in the second month. Then this rent of 1000Rs will be considered for 1st month. But this counts as late payment for the first month's fees, and hence he will have to pay Rs. 100 for that. And since the payment he made in the second month is not accounted for the second month, but rather for the first month, he will incur a fine of Rs.100 even for the second month. 

He has not paid any of the fines so far. Can you please help in finding Chef total due (all the fines, plus all the unpaid maintenance fees) that he has to pay to apartment? 

-----Input-----
First line of the input contains an integer T denoting number of test cases. The description of T test cases follows.
The first line of each test cases contains an integer N denoting the number of months for which you have to calculate the total amount of money that Chef has to pay at the end of the n month to clear all of his dues.
Next line of each test case contains N space separated integers (each of them can be either 0 or 1) denoting whether Chef paid the 1000Rs fees in the corresponding month or not. If the corresponding integer is 1, it means that Chef paid the maintenance fees for that month, whereas 0 will mean that Chef did not pay the maintenance fees that month.

-----Output-----
For each test case, output a single integer denoting the total amount including fine that Chef has to pay.

-----Constraints-----Constraints
- 1 ≤ T ≤ 25
- 0 ≤ Ai ≤ 1

-----Subtasks-----
Subtask #1 (30 points)
- 1 ≤ N ≤ 103

Subtask #2 (70 points)
- 1 ≤ N ≤ 105

-----Example-----
Input
4
2
1 1
2
0 0
3
0 1 0
2
0 1

Output
0
2200
2300
1200

-----Explanation-----
Example case 1. Chef paid maintenance fees for both the months. So, he does not have any dues left.
Example case 2. Chef did not pay the maintenance fees for any of the months. For the first month, he has to pay 1000Rs, and 100Rs fine as a late payment. For second month payments, he just have to pay 1100Rs. So, in total he has a due of 1100 + 1100 = 2200 Rs.
Example case 3. In the first month, Chef did not pay his maintenance fees. He paid the maintenance of first in the second month. So, he paid a fine of 100Rs for first month. For second and third month, Chef did not pay the maintenance fees. So, he has to pay 1000Rs + 100Rs (of fine) for second month and only 1000Rs + 100Rs (of fine) for third month. In total, Chef has got to pay 100 + 1100 + 1100 = 2300 Rs. 
Example case 4. In the first month, Chef did not pay his maintenance fees. He paid the maintenance of first in the second month. So, he paid a fine of 100Rs for first month. For second month, Chef did not pay the maintenance fees. So, he has to pay 1000Rs + 100Rs (of fine) for second month. In total, Chef has got to pay 100 + 1100 = 1200 Rs.

Source: codechef | Difficulty: EASY
Tags: Mathematics


Solutions:
for i in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	amount = p.count(0) * 1000
	if p.count(0) != 0:
		q = p.index(0)
		print(100 * (n - q) + amount)
	else:
		print(amount)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	total = 0
	c = 0
	for i in range(0, len(l)):
		if l[i] == 0:
			total += 1100
			c = 100
		elif l[i] == 1:
			total += c
		else:
			continue
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	rent = input().split(' ')
	(not_paid, to_pay) = (0, 0)
	for j in range(n):
		if rent[j] == '0':
			not_paid += 1
		elif rent[j] == '1':
			if not_paid != 0:
				to_pay += 100
	print(to_pay + not_paid * 1100)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	total_maintenance = 1000 * a.count(0)
	try:
		fine = 100 * (len(a) - a.index(0))
	except:
		fine = 0
	print(total_maintenance + fine)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	r = (n - l.count(1)) * 1000
	for i in range(n):
		if l[i] == 0:
			c = (n - i) * 100
			break
	print(r + c)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l.count(1) == n:
		print(0)
	elif l.count(0) == n:
		print(1100 * n)
	else:
		print((n - l.index(0)) * 100 + l.count(0) * 1000)


for j in range(int(input())):
	N = int(input())
	n = list(map(int, input().split()))
	total = 0
	count1 = 0
	count2 = 0
	count = 0
	for i in n:
		if i == 0:
			count1 += 1
			total += 1100
		elif i == 1 and count1 > 0:
			count2 += 1
			count += 1
		else:
			total += 0
	print(total + count * 100)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if 0 in l:
		ind = l.index(0)
		s = 100 * (n - ind)
		for i in range(ind, n):
			if l[i] != 1:
				s += 1000
		print(s)
	else:
		print('0')


for _ in range(int(input())):
	n = int(input())
	l = list(input().split())
	c0 = l.count('0')
	if '0' in l:
		print(1000 * c0 + 100 * (n - l.index('0')))
	else:
		print(0)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	one = 0
	zero = l.count(0)
	for i in l:
		if i == 1:
			one = one + 1
		else:
			break
	print(1000 * zero + 100 * (n - one))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = l.count(0)
	p = 0
	for i in range(n):
		if l[i] == 0:
			p = n - i
			break
	print(o * 1000 + p * 100)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		arr = list(map(int, input().split(' ')))[:N]
		due = 0
		firstduemonth = 0
		zero = True
		i = 0
		while i < N:
			if arr[i] == 0:
				if zero:
					zero = False
					firstduemonth = i + 1
				due += 1
			i += 1
		fine = 0 if firstduemonth == 0 else (N + 1 - firstduemonth) * 100
		print(1000 * due + fine)
main()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = l.count(0)
	b = l.count(1)
	if 0 in l:
		s = n - l.index(0)
	else:
		s = 0
	print(s * 100 + a * 1000)


for _ in range(int(input())):
	a = int(input())
	n = list(map(int, input().split()))
	c = a
	for i in range(a):
		if n[i] == 0:
			c = i
			break
	print(n.count(0) * 1000 + (a - c) * 100)


def solve(n, lst):
	s = 0
	l = 0
	for i in range(n):
		if lst[i] == 1:
			s += l
		else:
			s += 1100
			l = 100
	print(s)
for _ in range(int(input())):
	n = int(input())
	solve(n, list(map(int, input().split())))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	fine = 0
	if a.count(1) == n:
		print(0)
	elif a.count(0) == n:
		print(1100 * n)
	else:
		for j in range(n):
			if a[j] == 0:
				fine = (n - j) * 100
				break
		print(a.count(0) * 1000 + fine)


for _ in range(int(input())):
	n = int(input())
	arr = input().split()
	i = 0
	while i != n and arr[i] != '0':
		i += 1
	sum = 0
	for j in range(i, n):
		if arr[j] == '0':
			sum += 1100
		else:
			sum += 100
	print(sum)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(0) == 0:
		print(0)
	else:
		zero = arr.index(0)
		print(arr.count(0) * 1000 + (n - zero) * 100)


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	for i in range(a):
		if l[i] == 0:
			b = i + 1
			c = a - b + 1
			d = l.count(1)
			a = a - d
			print(a * 1000 + 100 * c)
			break
	else:
		print(0)


for i in range(int(input())):
	n = int(input())
	statement = list(map(int, input().split()))
	s = 1000 * statement.count(0)
	k = 0
	if statement[0] == 0:
		s = s + 100 * len(statement)
	elif statement[0] == 1 and statement.count(0) != 0:
		for j in range(n):
			if statement[j] == 0:
				k = j
				break
		s = s + (len(statement) - k) * 100
	print(s)


for i in range(int(input())):
	x = int(input())
	y = input().split()
	if '0' in y:
		print(100 * (x - y.index('0')) + y.count('0') * 1000)
	else:
		print(0)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if 0 not in a:
		print(0)
	elif 1 not in a:
		print(n * 1100)
	else:
		p = a.index(0)
		b = a[p:]
		print(len(b) * 100 + b.count(0) * 1000)


t = int(input())
for tc in range(t):
	n = int(input())
	l = list(map(str, input().split()))
	s = l.count('0')
	d = 0
	for j in l:
		if j == '1':
			d += 1
		else:
			break
	print(s * 1000 + (n - d) * 100)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	fine = 0
	total = 0
	due = 0
	for i in range(n):
		if a[i] == 0:
			fine += 1
			due += 1
		elif a[i] == 1 and due > 0:
			due += 1
	total = 1000 * fine + due * 100
	print(total)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	fz = False
	h = 0
	m = 0
	for i in a:
		if i == 0 and fz == False:
			fz = True
			h = h + 1
			m = m + 1
		elif fz == True and i == 1:
			h = h + 1
		elif fz == True and i == 0:
			h = h + 1
			m = m + 1
	print(m * 1000 + h * 100)


for _ in range(int(input())):
	n = int(input())
	pmon = list(map(int, input().split()))
	if pmon.count(0) == 0:
		print(0)
	else:
		for i in range(n):
			if pmon[i] == 0:
				temp = i
				break
		if temp == n - 1:
			c = 0
		elif temp == n - 2 and pmon[n - 1] == 1:
			c = 1
		else:
			l = pmon[temp + 1:]
			c = l.count(1)
		print(1100 * pmon.count(0) + 100 * c)


for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	zind = n
	zflag = False
	zcount = 0
	for (i, ele) in enumerate(arr):
		if ele == 0:
			zcount += 1
			if not zflag:
				zflag = True
				zind = i
	tot = 1000 * zcount + 100 * (n - zind)
	print(tot)


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	s = k = 0
	for j in b:
		if j == 0:
			s += 1100
			k = 100
		elif j == 1:
			s += k
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	total = 0
	late = False
	for i in a:
		if not i:
			total += 1000
			late = True
		if late:
			total += 100
	print(total)


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	c = 0
	if arr.count(0) == 0:
		print(0)
	else:
		for i in range(len(arr)):
			if arr[i] == 0:
				c = c + 1100
			elif c > 1000:
				c = c + 100
		print(c)
	t = t - 1


nt = int(input())
for _ in range(nt):
	n = int(input())
	a = []
	sm = 0
	zero = 0
	a = list(map(int, input('').strip().split()))[:n]
	for e in a:
		if int(e) == 1 and zero:
			sm += 100
		elif int(e) == 0:
			sm += 1100
			zero = 1
	print(sm)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	c = 0
	flag = 0
	for i in range(n):
		if l1[i] == 0:
			c += 1100
			flag = 1
		elif l1[i] == 1:
			if flag == 1:
				c += 100
	print(c)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	late = False
	tot = 0
	for i in range(len(A)):
		if not late:
			if A[i] == 0:
				tot += 1100
				late = True
		elif A[i] == 0:
			tot += 1100
		else:
			tot += 100
	print(tot)


for _ in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	tho = 1000 * p.count(0)
	try:
		iz = p.index(0)
		hun = 100 * (len(p) - iz)
	except:
		hun = 0
	print(tho + hun)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	s = l.count(0) * 1000
	for i in range(n):
		if l[i] == 0:
			s += (n - i) * 100
			break
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1 and a[0] == 1:
		print(0)
	else:
		v = False
		for i in range(n):
			if a[i] == 0:
				v = i
				break
		v = (n - v) * 100
		v1 = a.count(0) * 1000
		print(v + v1)


t = int(input())
for i in range(0, t):
	p = 0
	c = 0
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(0, n):
		if a[j] == 0:
			c = n - j
			break
	for k in range(0, n):
		if a[k] == 0:
			p = p + 1
	print(p * 1000 + c * 100)


for h in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	if l.count(1) == n:
		print(0)
	else:
		for i in l:
			if i == 0:
				s += 1100
			elif s != 0:
				s += 100
		print(s)


for i in range(int(input())):
	a = int(input())
	b = input().split()
	if '0' in b:
		print(100 * (a - b.index('0')) + b.count('0') * 1000)
	else:
		print(0)


T = int(input())
for i in range(T):
	N = int(input())
	Ai = list(map(int, input().split()))
	payment = 0
	l = 0
	if Ai.count(0) == N:
		payment = 1100 * N
	elif Ai.count(1) == N:
		payment = 0
	else:
		for k in Ai:
			if k == 0:
				if l == 0:
					ind = Ai.index(k)
					x = Ai[ind:]
					zeros = x.count(0)
					ones = x.count(1)
					payment = zeros * 1100 + ones * 100
					l = 1
				else:
					continue
			else:
				continue
	print(payment)


T = int(input())
for i in range(T):
	N = int(input())
	A = [int(i) for i in input().split()]
	m = 0
	for i in range(N):
		if A[i] == 0:
			m = m + 1000
		for i in range(N):
			if A[i] == 0:
				k = len(A) - i
				break
			else:
				k = 0
	n = m + k * 100
	print(n)


try:
	for _ in range(int(input())):
		N = int(input())
		Log = input().split()
		if '0' in Log:
			print(100 * (N - Log.index('0')) + Log.count('0') * 1000)
		else:
			print(Log.count('0') * 1000)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	total_rent = 0
	zcount = 0
	ocount = 0
	oAo = 0
	for i in arr:
		if i == 0:
			zcount += 1
			total_rent += 1100
		elif i == 1 and zcount > 0:
			ocount += 1
			oAo += 1
		else:
			total_rent += 0
	print(total_rent + oAo * 100)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = l.count(0)
	m = l.count(1)
	if 0 in l:
		s = n - l.index(0)
	else:
		s = 0
	print(s * 100 + k * 1000)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = l.count(1)
	q = l.count(0)
	if 0 in l:
		s = n - l.index(0)
	else:
		s = 0
	print(s * 100 + q * 1000)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = l.count(0)
	c = 0
	for i in range(n):
		if l[i] == 0:
			c = i
			break
		else:
			c = n
	g = (n - c) * 100
	print(g + k * 1000)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	p = n
	for i in range(n):
		if l[i] == 0:
			p = i
			break
	print((n - p) * 100 + (n - sum(l)) * 1000)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	if l.count(1) == n:
		print(0)
	else:
		print(l.count(0) * 1000 + (n - l.index(0)) * 100)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if len(set(l)) == 1 and l[0] == 1:
		print(0)
	elif len(set(l)) == 1 and l[0] == 0:
		print(n * 1100)
	else:
		f = 1
		c = 0
		for j in range(n):
			if l[j] == 1 and f == 0:
				c = c + 100
			elif l[j] == 0:
				c = c + 1100
				f = 0
		print(c)


for _ in range(int(input())):
	x = int(input())
	l1 = list(map(int, input().split()))
	c = 0
	if 0 in l1:
		a = l1.index(0)
		zero = l1.count(0)
		penalty = 100 * (x - a)
		print(zero * 1000 + penalty)
	else:
		print(0)


for tc in range(int(input())):
	n = int(input())
	f = list(map(int, input().split()))
	firstzero = 0
	fines = 0
	pay = 1000 * f.count(0)
	if f.count(0) > 0:
		firstzero = f.index(0)
		fines = (len(f) - firstzero) * 100
	pay = pay + fines
	print(pay)


for t in range(int(input())):
	total = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(0, n):
		if a[i] == 0:
			total = total + 1100
		elif total >= 1100:
			total = total - 1000
			total = total + 1100
	print(total)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	flg = 0
	for i in range(n):
		if l[i] == 0:
			c += 1100
			flg = 1
		elif l[i] == 1:
			if flg == 1:
				c += 100
	print(c)


t = int(input())
for i in range(t):
	c0 = 0
	cf = 0
	n = int(input())
	a = list((int(x) for x in input().split(' ')))
	for j in a:
		if j == 0:
			c0 += 1
			cf += 1
		elif j == 1 and cf > 0:
			cf += 1
	total = 1000 * c0 + cf * 100
	print(total)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	fine = 0
	tot = 0
	past = 0
	for i in range(n):
		if a[i] == 0:
			fine += 1
			past += 1
		elif a[i] == 1 and past > 0:
			fine += 1
		else:
			tot += 0
	tot = past * 1000 + fine * 100
	print(tot)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = 1000 * lis.count(0)
	for i in range(n):
		if lis[i] == 0:
			ans += (n - i) * 100
			break
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c0 = a.count(0)
	c1 = a.count(1)
	count = 0
	for j in a:
		if j == 1:
			count += 1
		else:
			break
	print(1000 * c0 + 100 * (n - count))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ones = 0
	con_ones = 0
	flag = False
	for i in l:
		if i != 1:
			break
		con_ones += 1
	for i in l:
		if i == 1:
			ones += 1
	due = 1000 * n - ones * 1000
	fine = 100 * n - con_ones * 100
	print(due + fine)


t = int(input())
while t != 0:
	n = int(input())
	l = list(input().split())
	if '0' in l:
		print(l.count('0') * 1000 + 100 * (n - l.index('0')))
	else:
		print(0)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = a.count(0)
	count = 0
	for i in a:
		if i == 1:
			count += 1
		else:
			break
	print(1000 * c + 100 * (n - count))


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

def answer(l):
	numberOfOnes = len(list(filter(lambda x: x == 1, l)))
	if numberOfOnes == len(l):
		return 0
	numberOfZeros = len(l) - numberOfOnes
	numberOfOnesInStarting = 0
	for i in l:
		if i == 0:
			break
		else:
			numberOfOnesInStarting += 1
	return 1000 * numberOfZeros + (len(l) - numberOfOnesInStarting) * 100
for i in paid:
	print(answer(i))


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	late = False
	lN = 0
	for i in L:
		if i == 0:
			late = True
		if late:
			lN += 1
	print(L.count(0) * 1000 + lN * 100)


n = int(input())
for i in range(n):
	l = int(input())
	m = map(int, input().split())
	due = 0
	amt = 0
	t = False
	for i in m:
		if t:
			due += 100
		if i == 0 and t != True:
			t = True
			due += 100
			amt += 1000
		elif i == 0:
			amt += 1000
		else:
			continue
	print(due + amt)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	total = 0
	for i in range(0, n):
		if s[i] == 0:
			total += 1100
		elif total >= 1100:
			total -= 1000
			total += 1100
	print(total)


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	due_month_start = -1
	for i in range(N):
		if L[i] == 0:
			due_month_start = i
			break
	if due_month_start == -1:
		print(L.count(0) * 1000)
	else:
		print(L.count(0) * 1000 + (N - due_month_start) * 100)


for _ in range(int(input())):
	n = int(input())
	statement = list(map(int, input().split()))
	fine = 0
	for (i, v) in enumerate(statement):
		if v == 0:
			fine = (n - i) * 100
			break
	total = fine + 1000 * statement.count(0)
	print(total)


def due(N):
	s = 0
	if N[0] == 1:
		i = 0
		while i < n and N[i] == 1:
			i += 1
		N = N[i:]
	for i in N:
		if i == 0:
			s += 1100
		else:
			s += 100
	return s
for _ in range(int(input())):
	n = int(input())
	N = list(map(int, input().split()))
	print(due(N))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	sum = 0
	flag = 0
	for i in range(0, n):
		if l[i] == 0:
			sum += 1100
			flag = 1
		elif l[i] == 1 and flag == 1:
			sum += 100
	print(sum)


for _ in range(int(input())):
	p = int(input())
	q = list(map(int, input().split()))
	l = False
	t = 0
	for k in range(len(q)):
		if not l:
			if q[k] == 0:
				t += 1100
				l = True
		elif q[k] == 0:
			t += 1100
		else:
			t += 100
	print(t)


_ = int(input())
for __ in range(0, _):
	n = int(input())
	a = list(map(int, input().split()))
	c_0 = 0
	x = n
	for i in range(0, n):
		if a[i] == 0:
			x = i
			break
	for j in range(0, n):
		if a[j] == 0:
			c_0 += 1
	print(c_0 * 1000 + (n - x) * 100)


t = int(input())
for ni in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	pos = n
	for i in range(n):
		if l[i] == 0:
			pos = i
			break
	if pos == n:
		print('0')
	else:
		print((n - i) * 100 + 1000 * (n - l.count(1)))


t = int(input())
for _ in range(t):
	n = int(input())
	fees = list(map(int, input().split()))
	ans = 1000 * fees.count(0)
	try:
		i = fees.index(0)
		fine = 100 * (n - i)
	except:
		fine = 0
	print(ans + fine)


x = int(input())
lt = []
for th in range(0, x):
	g = int(input())
	jk = str(input())
	hk = jk.split(' ')
	gb = []
	for mm in hk:
		gb.append(int(mm))
	lt.append(gb)
for nn in lt:
	rent = 0
	due = 0
	lup = 1
	for bvc in nn:
		if bvc == 0:
			due += 100
			lup = 0
		elif lup == 1:
			rent += 1000
		else:
			due += 100
			rent += 1000
	ynk = len(nn) * 1000 - rent
	print(ynk + due)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	if 0 in s:
		print((n - s.index(0)) * 100 + 1000 * s.count(0))
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	to_pay = a.count(0) * 1000
	paid = True
	fines = 0
	for i in range(len(a)):
		if a[i] == 0:
			paid = False
			fines += 100
		elif not paid:
			fines += 100
	print(to_pay + fines)


for _ in range(int(input())):
	N = int(input())
	inp_arr = tuple((int(i) for i in input().strip().split()))
	fine = 0
	maxMaint = 1000 * N
	for i in range(N):
		if inp_arr[i] == 0:
			if fine == 0:
				fine = 100 * (N - i)
		else:
			maxMaint -= 1000
	print(maxMaint + fine)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = n
	for j in range(n):
		if l[j] == 0:
			a = j
			break
	print(l.count(0) * 1000 + (n - a) * 100)