You are given a digital clock with $n$ digits. Each digit shows an integer from $0$ to $9$, so the whole clock shows an integer from $0$ to $10^n-1$. The clock will show leading zeroes if the number is smaller than $10^{n-1}$.

You want the clock to show $0$ with as few operations as possible. In an operation, you can do one of the following:

decrease the number on the clock by $1$, or

swap two digits (you can choose which digits to swap, and they don't have to be adjacent).

Your task is to determine the minimum number of operations needed to make the clock show $0$.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$).

The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — number of digits on the clock.

The second line of each test case contains a string of $n$ digits $s_1, s_2, \ldots, s_n$ ($0 \le s_1, s_2, \ldots, s_n \le 9$) — the number on the clock.

Note: If the number is smaller than $10^{n-1}$ the clock will show leading zeroes.


-----Output-----

For each test case, print one integer: the minimum number of operations needed to make the clock show $0$.


-----Examples-----

Input
7
3
007
4
1000
5
00000
3
103
4
2020
9
123456789
30
001678294039710047203946100020
Output
7
2
0
5
6
53
115


-----Note-----

In the first example, it's optimal to just decrease the number $7$ times.

In the second example, we can first swap the first and last position and then decrease the number by $1$.

In the third example, the clock already shows $0$, so we don't have to perform any operations.

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

Starter code:

Solutions:
for i in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	for i in s:
		if i != '0':
			x += 1
			x += int(i)
	if x == 0:
		print(x)
	elif s[-1] != '0':
		print(x - 1)
	else:
		print(x)


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

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

def getint():
	return int(input())

def solve():
	n = getint()
	s = input()
	ops = 0
	for k in range(n - 1):
		i = s[k]
		if int(i) > 0:
			ops += int(i) + 1
	if int(s[-1]) > 0:
		ops += int(s[-1])
	print(ops)
for t in range(getint()):
	solve()


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	dem = 0
	res = 0
	for x in s:
		if x != '0':
			dem += 1
			res += int(x)
	res += dem
	if s[n - 1] != '0':
		res -= 1
	print(res)


for i in range(int(input())):
	n = int(input())
	list1 = list(map(int, list(input())))
	count = 0
	for j in range(n - 1):
		if list1[j] != 0:
			count += 1
	print(sum(list1) + count)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	for i in range(len(s)):
		if s[i] != '0':
			ans += int(s[i]) - int('0')
			if i != n - 1:
				ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	p = 0
	a = 0
	for i in range(n):
		p += int(s[i])
		if i != n - 1 and s[i] != '0':
			p += 1
	print(p)


t = int(input())
while t > 0:
	num = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	l = int(input())
	cl = str(input())
	val = 0
	for i in range(0, l):
		num[int(cl[i])] += 1
		val += int(cl[i])
	print(val + sum(num) - num[0] - 1 if cl[-1] != '0' else val + sum(num) - num[0])
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input()))
	print(sum(s) + n - s.count(0) - (s[-1] != 0))


for _ in range(int(input())):
	l = int(input())
	b = input()
	ans = 0
	for i in range(l):
		if b[i] != '0':
			ans += 1 + int(b[i])
			if i == l - 1:
				ans -= 1
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	x = int(s[-1])
	ss = 0
	nz = 0
	for i in range(n):
		if int(s[i]) != 0:
			ss += int(s[i])
			nz += 1
	if x == 0:
		print(ss + nz)
	else:
		print(ss + nz - 1)
	t -= 1


import sys, os, io
I = input
for tc in range(1, 1 + int(I())):
	n = int(I())
	l = list(map(int, list((c for c in I().rstrip()))))
	op = sum(l)
	if op == 0:
		print(0)
		continue
	if l[-1] != 0:
		op -= 1
	for c in l:
		if c > 0:
			op += 1
	print(op)


for _ in range(int(input())):
	n = input()
	n = input()
	ans = 0
	for (idx, val) in enumerate(n):
		if int(val) != 0:
			ans += int(val)
			if idx != len(n) - 1:
				ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(input())
	ans = 0
	a = 0
	f = 0
	for i in range(n):
		ans = ans + int(l[i])
		if l[i] != '0':
			f = 1
		if f == 1 and l[i] != '0':
			ans = ans + 1
	if l[-1] != '0':
		ans = ans - 1
	print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	A = input()
	answer = 0
	for j in range(0, n):
		if int(A[j]) > 0:
			answer += int(A[j])
			if j < n - 1:
				answer += 1
	print(answer)


for _ in range(int(input())):
	n = int(input())
	s = input()[:n][::-1]
	res = 0
	for i in range(n):
		if i == 0 or s[i] == '0':
			res += int(s[i])
			continue
		res += int(s[i]) + 1
	print(str(res) + '\n')


for ighj in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	x += int(s[-1])
	for i in range(n - 2, -1, -1):
		if s[i] != '0':
			x += int(s[i]) + 1
	print(x)


testcase = int(input())
for i in range(testcase):
	total = 0
	cnt = 0
	n = int(input())
	s = input()
	for j in s:
		if j != '0':
			total = total + int(j)
			cnt += 1
	if s[n - 1] == '0':
		total = total + cnt
	else:
		total = total + (cnt - 1)
	print(total)


import sys
input = sys.stdin.readline

def solve():
	input()
	a = input().strip()
	print(sum(map(int, a)) + len(a) - 1 - a[:-1].count('0'))
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input()))
	print(sum(s) + n - s.count(0) - (s[-1] != 0))


for i in range(0, int(input())):
	n = int(input())
	s = input()
	l = list(s)
	if int(l[-1]) > 0:
		ex = 1
	else:
		ex = 0
	su = 0
	c = 0
	ze = 0
	for i in s:
		if int(i) > 0:
			su = su + int(i)
			c += 1
		else:
			ze += 1
	if ze == n:
		print(0)
	else:
		print(su - ex + c)


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 ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

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

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
for _ in range(int(input()) if True else 1):
	n = int(input())
	s1 = [int(k) for k in input()]
	ans = sum(s1)
	if s1.count(0) == n:
		print(ans)
	else:
		print(ans + n - s1.count(0) - (s1[-1] != 0))


for i in range(int(input())):
	x = int(input())
	y = list(map(int, input()))
	t = [i for i in y if i]
	l = len(t) - 1 if y[-1] != 0 else len(t)
	print(sum(t) + l)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	arr = []
	for j in range(len(s)):
		arr.append(int(s[j]))
	count = 0
	sum = 0
	if arr[len(arr) - 1] != 0:
		count = -1
	for j in range(len(arr)):
		if arr[j] != 0:
			count += 1
		sum += arr[j]
	print(count + sum)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = list(map(int, input().strip()))
	su = sum(s) + (n - s.count(0))
	if s[n - 1] != 0:
		su -= 1
	print(su)


for _ in range(int(input())):
	n = int(input())
	s = list(input().strip())
	ans = 0
	if n != 0:
		ans += ord(s[-1]) - 48
		s[-1] = '0'
	for i in range(n):
		if s[i] != '0':
			ans += 1
			ans += ord(s[i]) - 48
	print(ans)


time = eval(input())
tz = []
for i in range(time):
	td = 0
	c = 0
	wei = input()
	num = input()
	zero = num.count('0')
	for j in range(1, 10):
		t = num.count(str(j))
		if t:
			c += 1
		td = td + j * t + t
	if num[-1] != '0':
		td -= 1
	tz.append(td)
for i in tz:
	print(i)


for _ in range(int(input())):
	n = int(input())
	a = input()
	ans = 0
	for i in a:
		x = int(i)
		if x != 0:
			ans += x + 1
	if int(a[-1]) != 0:
		ans -= 1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()[:-1]
	ans = 0
	for si in s[:-1]:
		if si != '0':
			ans += int(si) + 1
	ans += int(s[-1])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	count = 0
	res = 0
	for i in range(len(s)):
		if s[i] != '0':
			count += 1
			res += int(s[i])
	if s[len(s) - 1] != '0':
		print(res + count - 1)
	else:
		print(res + count)


def func(a):
	s = 0
	for i in a:
		if i != '0':
			s += int(i) + 1
	if a[len(a) - 1] != '0':
		s -= 1
	return s
n = int(input())
a = []
b = []
for i in range(n):
	a.append(int(input()))
	b.append(input())
for i in b:
	print(func(i))


for i in range(int(input(''))):
	n = int(input())
	d = input()
	d = d[::-1]
	c = int(d[0])
	for j in range(1, n):
		if int(d[j]) > 0:
			c += int(d[j])
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, list(input())))
	ans = 0
	for i in range(n):
		if i == n - 1:
			ans += s[i]
		elif s[i] != 0:
			ans += s[i] + 1
	print(ans)


def solve():
	n = int(input())
	s = input()
	l = s[:]
	lst = list(map(int, l))
	answer = lst[-1]
	lst[-1] = 0
	for i in lst:
		if i != 0:
			answer += i
			answer += 1
	print(answer)
t = int(input())
while t:
	solve()
	t -= 1


def get_index(string):
	for i in range(len(string)):
		if string[i] != '0':
			return i
	return -1
for _ in range(int(input())):
	n = int(input())
	string = input()
	count = 0
	while True:
		if string[-1] == '0':
			indx = get_index(string)
			if indx == -1:
				break
			count += 1
			string = string[:indx] + '0' + string[indx + 1:-1] + string[indx]
		else:
			count += int(string[-1])
			string = string[:-1] + '0'
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	r = 0
	for j in range(n):
		if s[j] != '0':
			if j == n - 1:
				r += int(s[j])
			else:
				r += int(s[j]) + 1
	print(r)


t = int(input())
results = []
for i in range(t):
	n = int(input())
	s = input()
	j = 1
	total = 0
	for c in s:
		total += int(c)
		if j != n and int(c) != 0:
			total += 1
		j += 1
	results.append(total)
print('\n'.join([str(i) for i in results]))


def count_op(n, string):
	c_op = 0
	lst = [int(x) for x in string]
	while not all((x == 0 for x in lst)):
		c_op += lst[-1]
		lst[-1] = [x for x in lst if x != 0][0]
		index = lst.index(lst[-1])
		lst[index] = 0
		if index != n - 1:
			c_op += 1
	return c_op
t = int(input())
for i in range(t):
	print(count_op(int(input()), input()))


import decimal
import os
import sys
from collections import Counter
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 ints_get():
	return map(int, input().strip().split())

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

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

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

def main():
	for _ in range(int(input())):
		n = int(input())
		s = [int(x) for x in input()]
		val = 0
		for i in range(n - 1):
			if s[i] > 0:
				val += s[i] + 1
		if s[n - 1] > 0:
			val += s[n - 1]
		output(val)
	return
main()


def main():
	for t in range(int(input())):
		n = int(input())
		clock = input()
		total = 0
		for i in reversed(clock):
			total += int(i) + (i != '0')
		print(total - int(clock[-1] != '0'))
main()


def solve():
	n = int(input())
	x = input()
	ans = sum((int(dig) + (n - i > 1) if int(dig) > 0 else 0 for (i, dig) in enumerate(x)))
	return ans

def main():
	num_tests = int(input())
	for t in range(1, num_tests + 1):
		print(solve())
main()


t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	cnt = 0
	dc = 0
	sc = len(x) - x.count('0')
	for i in x:
		if i != '0':
			dc += int(i)
	if x[-1] != '0':
		sc -= 1
	print(sc + dc)


for i in range(int(input())):
	a = int(input())
	b = input()
	c = 0
	for j in range(a - 1, -1, -1):
		if j == a - 1:
			if b[j] != '0':
				c = c + int(b[j])
		elif b[j] != '0':
			c = c + int(b[j]) + 1
	print(c)


for _ in range(int(input())):
	input()
	s = input()
	x = s[-1]
	s = s.replace('0', '')
	l = len(s)
	a = 0
	for i in s:
		a += int(i)
	if x == '0':
		print(a + l)
	else:
		print(a + l - 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	z = 0
	fl = 0
	lz = 0
	num = 0
	for i in s:
		if i != '0':
			num += int(i)
		else:
			z += 1
	n -= z
	if s[-1] == '0':
		print(num + n)
	else:
		print(num + n - 1)


import os, sys, math
from io import BytesIO, IOBase
ip = lambda : input()
it = lambda : int(input())
ma = lambda : map(int, input().split(' '))
li = lambda : list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
md = 998244353

def f(x):
	z = 0
	l = len(x)
	for i in range(l):
		z += int(x[i]) + 1
	return z - 1

def main():
	for _ in range(int(input())):
		n = it()
		arr = [int(x) for x in ip()]
		z = 0
		for i in range(n):
			a = arr[i]
			if a:
				z += a + 1
		if arr[-1]:
			z -= 1
		print(z)
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 copy
import bisect

def solve():
	n = int(input())
	string = input()
	sum = int(string[-1])
	for i in range(len(string) - 2, -1, -1):
		x = int(string[i])
		if x != 0:
			sum += x + 1
	print(sum)
t = 1
t = int(input())
while t:
	t -= 1
	solve()


def swap(index_1, index_2, arr):
	temp = arr[index_1]
	arr[index_1] = arr[index_2]
	arr[index_2] = temp

def programcal(y, z):
	arr = []
	m = z
	for i in range(y):
		t = m % 10
		arr.append(t)
		m = m // 10
	arr.reverse()
	(j, count) = (0, 0)
	while j < y:
		if arr[y - 1] == 0:
			if arr[j] == 0:
				j = j + 1
			else:
				swap(y - 1, j, arr)
				count = count + 1
				j = j + 1
		elif arr[j] == 0:
			if j == y - 1:
				break
			else:
				j = j + 1
		else:
			temp = arr[y - 1]
			arr[y - 1] = 0
			if j == y - 1:
				count = count + temp
				j = j + 1
			else:
				swap(j, y - 1, arr)
				count = count + temp + 1
				j += 1
	print(count)
x = int(input())
l = 0
arr1 = []
arr2 = []
while l < x:
	y = int(input())
	arr1.append(y)
	z = int(input())
	arr2.append(z)
	l = l + 1
for i in range(x):
	programcal(arr1[i], arr2[i])


for _ in range(int(input())):
	n = int(input())
	a = str(input())
	k = 0
	if int(a[-1]) == 0:
		k += 1
	for i in range(len(a)):
		if int(a[i]) != 0:
			k += 1
			k += int(a[i])
	print(k - 1)


import sys
import math
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	line = [int(x) for x in sys.stdin.readline().strip()]
	cnt = sum(line)
	for x in line[:-1]:
		if x != 0:
			cnt += 1
	print(cnt)


test = int(input())
for i in range(test):
	n = int(input())
	s = input()
	s = [int(i) for i in s]
	count = sum(s)
	for i in s:
		if i != 0:
			count += 1
	if s[-1] != 0:
		print(count - 1)
	else:
		print(count)


def noOfOperations(num, n):
	nums = []
	nums[:0] = num
	for i in range(n):
		nums[i] = int(nums[i])
	count = nums[n - 1]
	for i in range(n - 1):
		if nums[i] != 0:
			count += nums[i] + 1
	return count
for _ in range(int(input())):
	n = int(input())
	num = input()
	ans = noOfOperations(num, n)
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	g = input()
	s = [int(i) for i in g]
	ans = 0
	if s[-1] != 0:
		ans += s[-1]
		s[-1] = 0
	mnsofar = 1000000000
	for turns in range(n):
		bestidx = -1
		mnsofar = 10 ** 9
		for i in range(n):
			if s[i] > 0 and s[i] < mnsofar:
				mnsofar = s[i]
				bestidx = i
		news = []
		for i in range(n):
			if i != bestidx:
				news.append(s[i])
		news.append(s[bestidx])
		if bestidx == -1:
			continue
		if bestidx != n - 1:
			ans += 1
		ans += s[bestidx]
		s[bestidx] = 0
		news[-1] = 0
		s = news[:]
	print(ans)


t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	ans = 0
	for i in range(n - 1):
		d = int(s[i])
		if d:
			ans += d + 1
	ans += int(s[-1])
	print(ans)


for _ in range(int(input())):
	nn = int(input())
	n = list(input())
	n = [int(ni) for ni in n]
	ans = 0
	for ni in n[:-1]:
		if ni == 0:
			continue
		ans += ni + 1
	ans += n[-1]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	init_num = input()
	res = 0
	for digit in init_num[:-1]:
		digit = int(digit)
		if digit != 0:
			res += digit + 1
	res += int(init_num[-1])
	print(res)


for i in range(int(input())):
	tot = 0
	k = 0
	n = int(input())
	m = input()
	for j in range(n - 1, -1, -1):
		if int(m[j]) > 0:
			tot += k + int(m[j])
			k = 1
		else:
			k = 1
	print(tot)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	res = 0
	for i in range(n):
		if int(s[i]) > 0 and i != n - 1:
			c += 1
		res += int(s[i])
	print(res + c)


def sol():
	n = int(input())
	dig = input()
	ans = 0
	cnt = 0
	for i in dig:
		if i != '0':
			ans += int(i)
			cnt += 1
	if dig[-1] != '0':
		ans += cnt - 1
	else:
		ans += cnt
	print(ans)
t = int(input())
while t > 0:
	sol()
	t -= 1


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

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

def read_one_float():
	return float(input().rstrip('\n'))

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

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

def count_operations(n, cur_str):
	non_zero = 0
	dig_sum = 0
	for ch in cur_str:
		if ch != '0':
			non_zero += 1
			dig_sum += int(ch)
	if not non_zero:
		print(0)
		return
	res = dig_sum + non_zero
	if cur_str[-1] != '0':
		res -= 1
	print(res)

def main():
	tests = read_one_int()
	for _ in range(tests):
		n = read_one_int()
		cur_str = read_str()
		count_operations(n, cur_str)
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	abs = int(s[-1])
	for i in range(n - 1):
		if s[i] != '0':
			abs += int(s[i]) + 1
	print(abs)


def calculate_amount_of_operations(input_string):
	amount_of_operations = 0
	for number in input_string:
		if number != '0':
			amount_of_operations += int(number) + 1
	if input_string[-1] != '0':
		amount_of_operations -= 1
	return amount_of_operations
tests_amount = int(input())
for _ in range(0, tests_amount):
	numbers_amount = int(input())
	input_string = input()
	print(calculate_amount_of_operations(input_string))


for _ in range(int(input())):
	n = int(input())
	clock = list(map(int, list(input())))
	operations = 0
	for digit in clock:
		if digit != 0:
			operations += digit + 1
	if clock[-1] != 0:
		operations -= 1
	print(operations)


t = int(input())
for q in range(t):
	n = int(input())
	s = [int(a) for a in input()]
	op = sum(s)
	for i in range(n - 1):
		if s[i] != 0:
			op += 1
	print(op)


for _ in range(int(input())):
	n = int(input())
	s = input()
	o = 0
	for i in range(n):
		if s[i] != '0':
			if i != n - 1:
				o += 1 + int(s[i])
			else:
				o += int(s[i])
	print(o)


for i in range(int(input())):
	n = int(input())
	number = list(map(int, list(input())))
	summ = sum(number)
	changes = n - number.count(0)
	if number[-1] != 0:
		changes -= 1
	print(summ + changes)


for _ in range(int(input())):
	x = int(input())
	y = list(map(int, input().strip()))
	print(sum(y) + (x - 1) - y[:-1].count(0))


t = int(input())
for _ in range(t):
	(n, s) = (int(input()), input())
	res = sum((int(d) + (1 if d != '0' and i != n - 1 else 0) for (i, d) in enumerate(s)))
	print(res)


n = int(input(''))
result_holder = list()
for i in range(n):
	result = 0
	input('')
	number_taker = list(input(''))
	for j in range(len(number_taker)):
		if number_taker[j] != '0':
			result += int(number_taker[j])
			if j + 1 != len(number_taker):
				result += 1
	result_holder.append(result)
for num in result_holder:
	print(num)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	moves = 0
	for j in range(n):
		if s[j] != '0' and j != n - 1:
			moves = moves + 1 + int(s[j])
		elif s[j] != '0' and j == n - 1:
			moves = moves + int(s[j])
	print(moves)


from itertools import dropwhile
for x in range(int(input())):
	n = int(input())
	s = list(map(lambda x: 0 if x == '0' else int(x) + 1, dropwhile(lambda x: x == '0', input())))
	if s:
		if s[-1] != 0:
			s[-1] -= 1
	print(sum(s))


def find():
	n = int(input())
	t = input()
	count = 0
	for i in t[:-1]:
		if i == '0':
			continue
		count += int(i) + 1
	return count + int(t[-1])
te = int(input())
for i in range(te):
	print(find())


for _ in range(int(input())):
	n = int(input())
	s = input()
	cu = 0
	k = 0
	for i in range(len(s)):
		if s[i] != '0':
			cu += int(s[i])
			if i != len(s) - 1:
				cu += 1
	print(cu)


t = int(input())
for i in range(t):
	n = int(input())
	num = input()
	count = 0
	for j in range(0, n):
		if int(num[j]) != 0:
			count += int(num[j])
			if j != n - 1:
				count += 1
	print(count)


output = ''
iters = int(input())
for i in range(iters):
	input()
	inp = input()
	ops = 0
	inp = list(inp)
	inp.reverse()
	for i in range(len(inp)):
		item = int(inp[i])
		ops += item
		if i != 0 and item != 0:
			ops += 1
	output += str(ops) + '\n'
print(output)


for t in range(int(input())):
	n = int(input())
	res = [int(x) for x in list(input())]
	total = 0
	for i in range(0, len(res)):
		if res[i] != 0 and i != len(res) - 1:
			total += res[i] + 1
		elif res[-1] == res[i]:
			total += res[i]
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	x = x[0:n]
	x = int(x)
	a = x
	c = 0
	c1 = 0
	while a != 0:
		r = a % 10
		if r != 0:
			if c1 >= 1:
				c += r + 1
			else:
				c += r
		c1 += 1
		a = a // 10
	print(c)


def printOperations(num, n):
	list1 = []
	list1[:0] = num
	for i in range(n):
		list1[i] = int(list1[i])
	count = list1[n - 1]
	for i in range(n - 1):
		if list1[i] != 0:
			count += list1[i] + 1
	print(count)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		num = input()
		printOperations(num, n)
main()


def get_input():
	al = []
	for c in range(int(input())):
		input()
		n = [int(i) for i in input()]
		al.append(n)
	return al

def solve(arr):
	counter = 0
	for a in arr[:-1]:
		if a != 0:
			counter += a + 1
	if arr[-1] != 0:
		counter += arr[-1]
	return counter

def main():
	arr_list = get_input()
	for n in arr_list:
		r = solve(n)
		print(r)
main()


t = int(input())
for i in range(t):
	k = int(input())
	s = input()
	sum = 0
	for j in range(len(s) - 1):
		if s[j] != '0':
			sum = sum + int(s[j])
			sum += 1
	if s[len(s) - 1] != '0':
		sum += int(s[len(s) - 1])
	print(sum)


numberOfTestCases = input()
numberOfTestCases = int(numberOfTestCases)
while numberOfTestCases > 0:
	mlen = input()
	mlen = int(mlen)
	minput = input()
	sum = 0
	for a in minput:
		num = int(a)
		sum += num
	numberOfTestCases -= 1
	result = sum + mlen
	zeroCount = 0
	for i in range(len(minput) - 1):
		if int(minput[i]) == 0:
			zeroCount += 1
	result = sum + mlen - zeroCount - 1
	if result < 0:
		result = 0
	print(result)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = sum((int(x) for x in s)) + n - s.count('0')
	if s[-1] != '0':
		print(ans - 1)
	else:
		print(ans)


t = int(input())
printarray = []
for i in range(t):
	n = int(input())
	s = input()
	numlist = [int(x) for x in s]
	thing = 0
	for j in range(n - 1):
		if numlist[j] != 0:
			thing += 1
	mysum = 0
	for asdf in numlist:
		mysum += asdf
	mysum += thing
	printarray.append(mysum)
for x in printarray:
	print(x)


n = int(input())
clock_list = list()
operations = 0
for i in range(n):
	n_item = int(input())
	clock = [int(i) for i in input()]
	clock_list.append(clock)

def mech(clock):
	operations = 0
	for k in range(len(clock)):
		while clock[-1] > 0:
			clock[-1] -= 1
			operations += 1
		if clock[k] > clock[-1]:
			(clock[k], clock[-1]) = (clock[-1], clock[k])
			operations += 1
	return operations
for l in range(n):
	print(mech(clock_list[l]))


import sys
read = lambda : sys.stdin.readline()
for _ in range(int(read())):
	n = int(read())
	num = [int(i) for i in list(input())]
	ans = [digit for digit in num if digit != 0]
	if len(ans) == 0:
		print(0)
		continue
	print(sum(ans) + (len(ans) - 1)) if num[-1] != 0 else print(sum(ans) + len(ans))


tests = int(input())
for _ in range(tests):
	digs = int(input())
	num = input()
	sum = 0
	pos = 0
	num = num[::-1]
	if num[0] != '0':
		sum += int(num[0])
	for i in range(1, digs):
		if num[i] != '0':
			sum += int(num[i]) + 1
	print(sum)


def f(n, s):
	count = 0
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			count = count + int(s[i])
		elif s[i] != '0':
			count = count + 1 + int(s[i])
	return count
x = int(input())
m = []
for i in range(x):
	z = int(input())
	y = input()
	m.append((z, y))
for i in range(x):
	print(f(m[i][0], m[i][1]))


import sys

def input():
	return sys.stdin.readline()[:-1]

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

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

def getIntList():
	return list(getIntIter())

def flush():
	sys.stdout.flush()
for _ in range(getInt()):
	n = getInt()
	z = input()
	s = 0
	for (pos, char) in enumerate(z):
		s += int(char)
		if int(char) > 0 and pos < n - 1:
			s += 1
	print(s)


t = int(input())
res = []
for i in range(t):
	n = int(input())
	num = input()
	r = 0
	for i in range(len(num) - 1):
		if int(num[i]) != 0:
			r += int(num[i]) + 1
	r += int(num[len(num) - 1])
	res.append(int(r))
print(*res, sep='\n')


for i in range(int(input())):
	n = int(input())
	s = input()
	print(sum([int(x) for x in s]) + n - s.count('0') - int(not s.endswith('0')))


def solve():
	n = int(input())
	digits = [int(x) for x in list(input())]
	result = 0
	for (i, digit) in enumerate(digits):
		if digit:
			result += digit + 1
	if digits[-1]:
		result -= 1
	return result
t = int(input())
result = []
for _ in range(t):
	result.append(solve())
for x in result:
	print(x)


num_tests = int(input())
for i in range(num_tests):
	num_digits = int(input())
	clock_time = input()
	num_operations = 0
	for i in range(num_digits - 1, -1, -1):
		dig = int(clock_time[i])
		if dig != 0:
			num_operations += dig
			if i < num_digits - 1:
				num_operations += 1
	print(num_operations)


for i in range(int(input())):
	n = int(input())
	s = input()
	ns = [int(i) for i in s]
	m = 0
	for (i, k) in enumerate(ns):
		if k != 0 and i != n - 1:
			m += 1
	print(sum(ns) + m)


flag = 1
while 1:
	try:
		if flag == 1:
			n = int(input())
		if n > 100 or n < 0:
			flag = 1
			continue
		temp = str(input())
		s = [int(i) for i in temp]
		if len(s) == n and 1 <= n <= 100:
			sum = 0
			for i in range(len(s)):
				if i == len(s) - 1:
					sum += s[i]
				elif s[i] > 0:
					sum += s[i] + 1
			print(sum)
			flag = 1
		elif len(s) == 1:
			n = s[0]
			flag = 0
	except EOFError:
		break


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	p = 0
	for i in range(n):
		if int(s[i]) > 0:
			p += int(s[i])
			if i == n - 1:
				continue
			else:
				c += 1
	print(p + c)


for x in range(int(input())):
	a = input()
	b = int(input())
	if b == 0:
		print(0)
	else:
		c = str(b)
		d = 0
		length = len(c) - c.count('0')
		for i in range(len(c)):
			d += int(c[i])
		if int(c[len(c) - 1]) == 0:
			print(d + length)
		else:
			print(d + length - 1)


t = int(input())
while t > 0:
	n = int(input())
	p = input()
	swap = 0
	count = 0
	sum = 0
	for i in range(len(p)):
		count = count + int(p[i])
	for i in range(len(p) - 1):
		if int(p[i]) != 0:
			sum = sum + 1
	swap = swap + sum
	print(swap + count)
	t = t - 1


n = int(input())
for i in range(1, n + 1):
	ans = 0
	cnt = 1
	k = int(input())
	s = input()
	for x in s:
		ans += int(x)
		if cnt != k and int(x) != 0:
			ans += 1
		cnt += 1
	del s
	del k
	print(str(ans) + '\n')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	num = input()
	if int(num) == 0:
		print(0)
	else:
		count = 0
		x1 = int(num[len(num) - 1])
		while x1 != 0:
			x1 -= 1
			count += 1
		for i in range(len(num) - 1):
			x = int(num[i])
			if x != 0:
				count += 1
			while x != 0:
				x -= 1
				count += 1
		print(count)


t = int(input())
for u in range(t):
	n = int(input())
	s = input()
	f = 1
	ans = 0
	for i in range(n):
		ans += int(s[i])
		if int(s[i]) != 0 and i != n - 1:
			ans += 1
	print(ans)


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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
		self.BUFSIZE = 8192

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

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

	def flush(self):
		if self.writable:
			self.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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 1000000007
for _ in range(inp()):
	n = inp()
	s = st()
	diff = 0
	ct = 0
	for i in range(n - 1):
		if s[i] != '0':
			ct += int(s[i]) + 1
	if s[n - 1] != '0':
		ct += int(s[n - 1])
	print(ct)


test_case = int(input())
for t in range(test_case):
	input()
	time_string = input()
	step = 0
	for i in range(len(time_string)):
		step += int(time_string[i])
		if time_string[i] != '0' and i < len(time_string) - 1:
			step += 1
	print(step)


for i in range(int(input())):
	num = int(input())
	x = input()
	sum = 0
	cnt = 0
	for i in range(num):
		sum += int(x[i])
	for i in range(num):
		if x[i] != '0':
			cnt += 1
	if x[num - 1] != '0':
		xo = cnt - 1
	else:
		xo = cnt
	ans = sum + xo
	print(ans)


def scan():
	return map(int, input().split())
for _ in range(int(input())):
	n = input()
	p = input()
	ans = 0
	l = len(p)
	for i in range(l):
		c = int(p[i])
		ans += c
		if i < l - 1 and c > 0:
			ans += 1
	print(ans)


for _ in range(int(input())):
	input()
	a = tuple(map(int, list(input())))
	if sum(a) == 0:
		print(0)
	elif a[-1] == 0:
		print(sum(a) + len(tuple(filter(lambda x: x != 0, a))))
	else:
		print(sum(a) + len(tuple(filter(lambda x: x != 0, a))) - 1)


def solve(numbers):
	factor = int(bool(numbers[-1]))
	return sum(numbers) + len(numbers) - numbers.count(0) - factor
t = int(input())
for case in range(t):
	a = input()
	print(solve(list(map(int, input()))))


for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input()]
	count = 0
	for i in range(n - 1):
		if arr[i] != 0:
			count += 1
	print(sum(arr) + count)


import math
t = int(input())
cases = []
for i in range(t):
	n = int(input())
	a = input()
	cases.append(list(a))

def answer(a):
	ans = 0
	for i in range(len(a)):
		if int(a[i]) != 0 and i != len(a) - 1:
			ans += 1
		ans += int(a[i])
	return ans
for i in cases:
	print(answer(i))


def estimate_changes(s, n):
	count = 0
	for (i, ch) in enumerate(s, 1):
		digit = int(ch)
		if digit > 0:
			count += digit
			if i < n:
				count += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(estimate_changes(s, n))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = 0
	for i in range(n - 1, -1, -1):
		if i == n - 1 and int(s[i]) > 0:
			ans += int(s[i])
		elif int(s[i]) > 0:
			ans = ans + int(s[i]) + 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	s = input()
	R = sum(map(int, s)) + (n - s.count('0')) - int(s[-1] != '0')
	print(R)


def f(s):
	n = 0
	n += int(s[-1])
	for i in s[:-1]:
		if int(i) != 0:
			n += int(i) + 1
	return n
a = []
for i in range(int(input())):
	input()
	s = input()
	a.append(f(s))
for i in a:
	print(i)


t = int(input())
for t in range(t):
	n = int(input())
	s = input()
	sumx = 0
	count = 0
	if s[n - 1] != '0':
		for i in range(0, n):
			sumx = sumx + int(s[i])
		for i in range(0, n):
			if s[i] != '0':
				count = count + 1
		ans = sumx + count
		print(ans - 1)
	else:
		for i in range(0, n):
			sumx = sumx + int(s[i])
		for i in range(0, n):
			if s[i] != '0':
				count = count + 1
		ans = sumx + count
		print(ans)


for pare in range(int(input())):
	leN = int(input())
	ch = input()
	P = 0
	if ch[-1] != '0':
		pere0 = leN - ch.count('0')
		vichet = sum([int(i) for i in ch])
		print(pere0 + vichet - 1)
	elif ch[-1] == '0':
		if ch.count('0') == leN:
			print(0)
		else:
			pere0 = leN - ch.count('0')
			vichet = sum([int(i) for i in ch])
			print(pere0 + vichet)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = int(s[-1])
	l = [int(s[i]) for i in range(n - 1) if s[i] != '0']
	c += sum(l) + len(l)
	print(c)


t = int(input())
while t:
	t -= 1
	dl = int(input())
	num = input()
	step = 0
	nz = dl - num.count('0')
	for c in num:
		step += int(c)
	step += nz
	if num[-1] != '0' and step > 0:
		step -= 1
	print(step)


in1 = lambda : int(input())
in2 = lambda : list(map(int, input().split()))
for i in range(in1()):
	(n, s) = (in1(), input())
	res = 0
	for j in range(n - 1):
		if s[j] != '0':
			res += 1
	for c in s:
		res += int(c)
	print(res)


tot = 0
tot = int(input())
temp = tot * 2
cases = []
while temp > 0:
	cases.append(input())
	if temp % 2 == 0:
		cases.pop()
	temp -= 1
for (i, x) in enumerate(cases):
	ans = 0
	for (j, y) in enumerate(cases[i]):
		if j == len(cases[i]) - 1:
			ans = ans + int(cases[i][j])
		elif int(cases[i][j]) in range(1, 10):
			ans = ans + 1 + int(cases[i][j])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ops = 0
	for i in range(n):
		if s[i] != '0':
			if i != n - 1:
				ops += 1
			ops += int(s[i])
	print(ops)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = str(input())
	sum = int(s[-1])
	s = s[:-1]
	while n > 1:
		if int(s[-1]):
			sum = sum + 1 + int(s[-1])
		s = s[:-1]
		n = n - 1
	print(sum)


for _ in range(int(input())):
	n = int(input())
	inp = input()
	arr = []
	for i in inp:
		if i != '0':
			arr.append(int(i))
	print(sum(arr) + len(arr) - 1 * int(inp[-1] != '0'))


from collections import Counter, defaultdict
from sys import stdin, stdout
import io, os, sys
input = stdin.readline
from collections import OrderedDict
mod = 998244353

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

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

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

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

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 * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for p in range(n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def writ(ss):
	stdout.write(str(ss) + '\n')

def mult(a, b, mod):
	return a % mod * (b % mod) % mod
for test in range(int(input())):
	n = intinput()
	s = strinput()
	ans = 0
	s = s[::-1]
	for i in range(n):
		if int(s[i]) > 0 and i > 0:
			ans += 1
		ans += int(s[i])
	writ(ans)


n = int(input())
for _ in range(n):
	x = int(input())
	y = input()
	y = list(y)
	l = []
	for i in y:
		l.append(int(i))
	c = l[x - 1]
	l[x - 1] = 0
	for i in l:
		if i != 0:
			c = c + i
			c = c + 1
	print(c)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	n = int(ip())
	s = [*map(int, ip().strip())]
	ans = sum(s) + n - s.count(0)
	if s[-1] == 0:
		print(ans)
	else:
		print(ans - 1)


for t in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	for i in s[:-1]:
		if i != '0':
			ans = ans + 1 + int(i)
	ans = ans + int(s[-1])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	d = int(input())
	l = []
	q = d
	while d > 0:
		r = d % 10
		l.append(r)
		d = d // 10
	t = l.count(0)
	s = len(l) - t
	w = sum(l)
	if q % 10 != 0:
		print(s + w - 1)
	else:
		print(s + w)


t = int(input())
while t:
	n = int(input())
	s = input()
	res = int(s[n - 1])
	for i in range(n - 2, -1, -1):
		res += int(s[i])
		if s[i] != '0':
			res += 1
	print(res)
	t -= 1


for iii in range(int(input())):
	n = int(input())
	x = input()
	cout = 0
	for i in x:
		if int(i) > 0:
			cout = cout + int(i) + 1
	if int(x[n - 1]) > 0:
		cout -= 1
	print(cout)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline()[:n]
	sys.stdout.write('%d\n' % (sum((int(i) for i in s)) + sum((i != '0' for i in s[:-1]))))


t = int(input())
for i in range(t):
	n = int(input())
	N = int(input())
	r = 0
	while N >= 10:
		last_digit = N % 10
		N -= last_digit
		N = int(str(N)[1:-1] + str(N)[0])
		r += last_digit + 1
	if 0 < N < 10:
		r += N
	print(r)


t = int(input())
for i in range(0, t):
	sum = 0
	n = int(input())
	s = input()
	for j in range(0, n - 1):
		if s[j] == '0':
			continue
		else:
			sum += int(s[j]) + 1
	sum += int(s[n - 1])
	print(sum)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, list(input())))
	res = s[-1]
	for i in s[:-1]:
		if i > 0:
			res += i + 1
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	g = 0
	d = 0
	for i in range(len(s)):
		g = g + int(s[i])
		if int(s[i]) == 0:
			d = d + 1
	if d != len(s):
		if int(s[len(s) - 1]) == 0:
			print(g + (len(s) - d))
		else:
			print(g + (len(s) - d - 1))
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	a = input()
	c = int(a[n - 1])
	for i in range(n - 1):
		if a[n - 2 - i] == '0':
			continue
		else:
			c += int(a[n - 2 - i]) + 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = input()
	out = []
	for i in range(n):
		if s[i] != '0':
			out.append(int(s[i]))
	if not out:
		print(0)
	else:
		cur = len(out) + sum(out)
		if s[-1] != '0':
			cur -= 1
		print(cur)


def test():
	n = int(input())
	s = input()
	sum = 0
	for x in s:
		sum += ord(x) - 48
		if x != '0':
			sum += 1
	if s[-1] != '0':
		sum -= 1
	print(sum)
	return 0
t = int(input())
for i in range(t):
	test()


for _ in range(int(input())):
	n = int(input())
	s = input()
	sm = 0
	for i in range(len(s) - 1, -1, -1):
		if int(s[i]) > 0:
			if i == n - 1:
				sm += int(s[i])
			else:
				sm += int(s[i]) + 1
	print(sm)


for _ in range(int(input())):
	a = input()
	s = list(map(int, input()))
	ans = s[-1]
	for x in s[:-1]:
		if x != 0:
			ans += x + 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	m = input()
	if m[-1] != '0':
		p0 = n - m.count('0')
		v = sum([int(i) for i in m])
		print(p0 + v - 1)
	elif m[-1] == '0':
		if m.count('0') == n:
			print(0)
		else:
			p0 = n - m.count('0')
			v = sum([int(i) for i in m])
			print(p0 + v)


num = int(input())
s = [0] * num
for i in range(num):
	j = int(input())
	st = input()
	if st[-1] != '0':
		s[i] = -1
	for k in st[::-1]:
		if k != '0':
			s[i] += 1 + int(k)
print(*s, sep='\n')


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

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

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

def solve():
	n = int(input())
	ss = [int(s) for s in input()]
	res = sum(ss) + n - ss.count(0)
	if ss[n - 1] != 0:
		res -= 1
	print(res)

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


tc = int(input())
while tc > 0:
	size = int(input())
	string = input()
	ans = 0
	for i in range(size):
		if int(string[i]) > 0:
			ans = ans + int(string[i])
			if i != size - 1:
				ans = ans + 1
	tc -= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = int(input())
	s = str(s)
	ans = 0
	for i in range(len(s) - 1, -1, -1):
		if int(s[i]) != 0 and i == len(s) - 1:
			ans += int(s[i])
		elif int(s[i]) != 0:
			ans += 1 + int(s[i])
	print(ans)


nt = int(input())
for i in range(nt):
	n = int(input())
	c = str(input())
	c = c[::-1]
	op = int(c[0])
	for j in c[1:]:
		if j != '0':
			op += 1 + int(j)
	print(op)


for _ in range(int(input())):
	n = int(input())
	s = input()
	assert len(s) == n
	r = int(s[-1])
	for c in s[:-1]:
		if c != '0':
			r += int(c) + 1
	print(r)


t = int(input())
while t:
	t -= 1
	s = int(input())
	n = list(map(int, input()))
	print(sum(n) + len(n) - n.count(0) - (n[-1] != 0))


t = int(input())

def solve():
	n = int(input())
	s = input()
	count = 0
	for x in s:
		if x != '0':
			count += int(x) + 1
	if s[-1] != '0':
		print(count - 1)
	else:
		print(count)
for y in range(t):
	solve()


for __ in range(int(input())):
	N = int(input())
	S = list(input())
	ops = -1 if S[-1] != '0' else 0
	for x in S[::-1]:
		if x != '0':
			ops += 1 + int(x)
	print(ops)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = [int(i) for i in s if i != '0']
	if s[n - 1] == '0':
		print(sum(a) + len(a))
	else:
		print(sum(a) + len(a) - 1)


for _ in range(int(input())):
	n = int(input())
	num = input()
	list1 = []
	list1[:0] = num
	list1 = list(map(int, list1))
	c = list1[n - 1]
	for i in range(n - 1):
		if list1[i] != 0:
			c += list1[i] + 1
	print(c)


def countdown(number: str) -> int:
	res = 0
	number = int(number)
	number = str(number)
	for i in range(1, 10):
		res += number.count(str(i)) * i
		res += number.count(str(i))
		res -= 1 if number[-1] == str(i) else 0
	return res
t = int(input())
for i in range(t):
	n = int(input())
	a = str(input())
	print(countdown(a))


def solve(n, s):
	sol = int(s[-1])
	for i in range(n - 2, -1, -1):
		if s[i] != '0':
			sol += 1 + int(s[i])
	return sol
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(solve(n, s))


Map = {str(k): k for k in range(10)}

def number_of_operations(number):
	Sum = 0
	n = len(number)
	consecutive_zeros = 0
	for i in range(n):
		if Map[number[i]] != 0:
			Sum += Map[number[i]] + 1
	if Map[number[-1]] != 0:
		Sum -= 1
	return Sum
numbers = []
test_num = int(input())
for i in range(test_num):
	n = int(input())
	numbers.append(input())
for i in range(test_num):
	print(number_of_operations(numbers[i]))


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(input().strip())
	arr = list(map(int, arr))
	totalPos = 0
	output = 0
	for i in range(n):
		if arr[i] > 0:
			output += arr[i]
			totalPos += 1
	change = 0
	curr = 0
	for i in range(n - 1, -1, -1):
		if arr[i] > 0 and curr > totalPos:
			change += 1
		curr += 1
	output += totalPos - (1 if arr[-1] != 0 else 0)
	ANS.append(str(output))
print('\n'.join(ANS))


for T in range(int(input())):
	n = int(input())
	s = input()
	count = 0
	for i in range(n):
		if s[i] != '0':
			if i < n - 1:
				count += 1
			count += ord(s[i]) - ord('0')
	print(count)


def solution():
	for t in range(int(input())):
		n = int(input())
		s = input()
		ans = 0
		isnzero = n - s.count('0')
		if s[-1] != '0':
			isnzero -= 1
		for e in s:
			ans += int(e)
		ans += isnzero
		print(ans)
	return
solution()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	n1 = int(input())
	s = str(n1)
	if s == '0':
		print(0)
		continue
	ans = 0
	while s != '':
		if len(s) == 1:
			ans += int(s[0])
			s = ''
		elif s[-1] == '0':
			t = s[0]
			s = s[1:len(s) - 1] + t
			ans += 1
		else:
			ans += int(s[-1])
			t = s[0]
			s = s[1:len(s) - 1] + t
			if s != '':
				ans += 1
		if s != '':
			s = str(int(s))
	print(ans)


for i in range(int(input())):
	n = int(input())
	x = input()
	t = [char for char in x]
	count = int(t[-1])
	for j in range(n - 2, -1, -1):
		if t[j] != '0':
			count += int(t[j]) + 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(input())
	calcSum = sum(map(int, nums))
	posNums = 0
	for i in nums:
		if i != '0':
			posNums += 1
	answer = 0
	if nums[-1] == '0':
		answer = posNums + calcSum
	else:
		answer = posNums + calcSum - 1
	print(answer)


t = int(input())
for i in range(t):
	n = input().rstrip()
	n = int(n)
	s = input().rstrip()
	count = 0
	if s[-1] != '0':
		count += int(s[-1])
	for c in s[0:n - 1]:
		if c != '0':
			count += int(c) + 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	s = int(a[n - 1])
	a = a[:n - 1]
	for j in range(n - 1):
		if a[j] != '0':
			s = s + int(a[j]) + 1
	print(s)


for i in range(int(input())):
	n = int(input())
	s = input()
	l = list(map(int, s))
	c = 0
	for i in l:
		if i != 0:
			c += 1
	if l[-1] == 0:
		print(sum(l) + c)
	else:
		print(sum(l) + c - 1)


def singleinput():
	R = int(input())
	return R

def strinput():
	R = str(input())
	return R

def intarray():
	As = list(map(int, input().split()))
	return As

def matrixinput(arr):
	As = list(map(int, input().split()))
	arr.append(As)
for i in range(singleinput()):
	n = singleinput()
	s = strinput()
	arr = [0] * 10
	for i in range(0, n):
		arr[int(s[i])] += 1
	val = 0
	for i in range(0, 10):
		val += arr[i] * i
	if arr[0] == n:
		print(0)
	elif int(s[-1]) != 0:
		print(val + sum(arr) - arr[0] - 1)
	else:
		print(val + sum(arr) - arr[0])


t = int(input())
for _ in range(t):
	n = int(input())
	c = input()
	a = 0
	for ch in c:
		if int(ch) != 0:
			a += int(ch) + 1
	if c[-1] != '0':
		a -= 1
	print(a)


def solve(numStr):
	numList = list(map(int, numStr))
	s = sum(numList)
	l = len(numList)
	lsb = numList[-1]
	zeros = numList.count(0)
	notzeros = l - zeros
	if lsb != 0:
		notzeros -= 1
	ans = s + notzeros
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	numStr = input().strip()
	ans = solve(numStr)
	print(ans)


for i in range(int(input())):
	n = int(input())
	s = str(input())
	count = 0
	sm = 0
	for j in range(n):
		if s[j] != '0':
			if s[n - 1] != '0' and j == n - 1:
				sm += int(s[j])
			else:
				count += 1
				sm += int(s[j])
	print(sm + count)


for s in [*open(0)][2::2]:
	print(sum((x > '0' for x in s[:-2])) + sum(map(int, s[:-1])))


t = input()
for i in range(int(t)):
	n = int(input())
	s = list(reversed(input()))
	ans = int(s[0])
	s[0] = '0'
	while s.count('0') != n:
		for j in range(n):
			if s[j] != '0':
				ans += int(s[j]) + 1
				s[j] = '0'
	print(ans)


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
cat = ''.join
catn = '\n'.join
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]

def solve():
	n = ri()
	s = rl()
	ans = 0
	for (i, c) in enum(s):
		if c == '0':
			continue
		ans += int(c)
		ans += i < n - 1
	return ans
t = ri()
for _ in range(t):
	print(solve())


n = int(input())
i = 0
listm = []
listx = []
while i < n:
	m = input()
	listm.append(m)
	x = input()
	listx.append(x)
	i = i + 1
k = l = t = 0
while k < n:
	x = listx[k]
	m = listm[k]
	while l < len(x):
		t = t + int(x[l])
		l = l + 1
	r = x.count('0', 0, len(x) - 1)
	t = t + int(m) - r
	print(t - 1)
	t = r = l = 0
	k = k + 1


def solve(s, n):
	ans = 0
	for i in range(n):
		x = int(s[i])
		if i == n - 1:
			ans += x
		elif x > 0:
			ans += x + 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(solve(s, n))


t = int(input())
for k in range(t):
	n = int(input())
	s = input()
	count = int(s[-1])
	for i in range(len(s) - 1):
		if s[i] != '0':
			count += int(s[i])
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	l = int(input())
	digit = input()
	c = 0
	k = l - digit.count('0')
	for i in range(l):
		c += int(digit[i])
	c += k
	if int(digit[-1]) != 0:
		c -= 1
	print(c)


n = int(input())
for i in range(n):
	count = 0
	len_num = int(input())
	num = str(input())
	for i in range(len_num):
		if num[i] != '0':
			count += int(num[i]) + 1
	if num[len_num - 1] != '0' and count > 0:
		count -= 1
	print(count)


def solve(idx=None):
	n = int(input())
	time = input()
	ans = 0
	for s in time[:-1]:
		if s != '0':
			ans += int(s) + 1
	ans += int(time[-1])
	print(ans)
for i in range(int(input())):
	solve(i)


import sys
input = sys.stdin.readline
from collections import deque
from itertools import combinations
t = int(input())
for i in range(t):
	n = int(input())
	s = input().strip()
	ans = 0
	for j in range(len(s)):
		if s[j] != '0':
			if j == len(s) - 1:
				ans += int(s[j])
			else:
				ans += int(s[j]) + 1
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	z = 0
	sm = 0
	c = 0
	for i in s[:len(s) - 1]:
		if int(i) == 0:
			z += 1
		else:
			c += 1
			sm += int(i)
	if int(s[len(s) - 1]) == 0:
		print(c + sm)
	else:
		print(int(s[len(s) - 1]) + c + sm)


t = int(input())
for i in range(0, t):
	ans = 0
	n = int(input())
	a = str(input())
	for j in range(0, n):
		if a[j] != '0':
			ans += int(a[j])
			if j < n - 1:
				ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	result = 0
	for j in range(len(s) - 1, -1, -1):
		if j == len(s) - 1:
			if int(s[j]) != 0:
				result += int(s[j])
				continue
		if int(s[j]) != 0:
			result += int(s[j]) + 1
	print(result)


from sys import stdin as f
t = int(next(f))
ans = []
for _ in range(t):
	n = int(next(f))
	s = [int(i) for i in next(f).strip()]
	res = 0
	if s[-1] != 0:
		res += s[-1]
		s[-1] = 0
	for i in range(n - 1):
		if s[i] != 0:
			(s[i], s[-1]) = (0, s[i])
			res += s[-1] + 1
			s[-1] = 0
		if all((si == 0 for si in s)):
			break
	ans.append(res)
print(*ans, sep='\n')


n = int(input())
a = [[0, ''] for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
	a[i][0] = int(input())
	a[i][1] = input()
	if int(a[i][1]) == 0:
		b[i] = 0
	else:
		for j in range(a[i][0]):
			if int(str(a[i][1])[j]) != 0:
				if j == a[i][0] - 1:
					b[i] += int(str(a[i][1])[j])
				else:
					b[i] += 1 + int(str(a[i][1])[j])
for i in range(n):
	print(b[i])


for _ in range(int(input())):
	n = int(input())
	k = list(input())
	l = [int(x) for x in k]
	c = n - l.count(0)
	if l[-1] == 0:
		pass
	else:
		c = c - 1
	print(sum(l) + c)


for s in [*open(0)][2::2]:
	print(sum((int(x) + (x > '0') for x in s[:-2])) + int(s[-2]))


def count_num():
	count = 0
	total = 0
	for el in eins:
		if el != '0':
			count += 1
			total += int(el)
	return (count, total)

def solve():
	count = 0
	(a, b) = count_num()
	if eins[-1] == '0':
		count += a + b
	else:
		count += a + b - 1
	return count
t = int(input())
for cases in range(t):
	n = int(input())
	eins = input()
	print(solve())


def countdown(number):
	sum = 0
	for num in number[:-1]:
		if num != '0':
			sum += 1 + int(num)
	sum += int(number[-1])
	return sum
t = int(input())
for _ in range(t):
	_ = int(input())
	number = input()
	print(countdown(number))


lan = []
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input()))
	if x[-1] == 0:
		ans = sum(x) + (n - x.count(0))
		lan.append(ans)
	else:
		ans = sum(x) + (n - x.count(0)) - 1
		lan.append(ans)
print(*lan, sep='\n')


def solve(number):
	number = str(number)
	operations = 0
	for (i, char) in enumerate(number):
		decimal = int(char)
		if decimal != 0:
			operations += decimal
			if i != len(number) - 1:
				operations += 1
	return operations
test_num = int(input())
output = list()
for i in range(test_num):
	decimal_num = int(input())
	number = int(input())
	output.append(solve(number))
for i in output:
	print(i)


n = int(input())
for _ in range(n):
	input()
	s = input()
	res = 0
	for c in range(len(s) - 1):
		res += int(s[c]) + 1 if int(s[c]) != 0 else 0
	res += int(s[-1])
	print(res)


def func(length, string):
	op = 0
	for j in string:
		if j != '0':
			op += int(j) + 1
	if not string.endswith('0'):
		op -= 1
	return op
for i in range(0, int(input())):
	print(func(int(input()), input()))


import sys
from math import sqrt, ceil, floor, gcd
from collections import Counter
input = lambda : sys.stdin.readline()

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

def str_arr():
	return list(map(str, input().split()))

def get_str():
	return map(str, input().split())

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

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

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

def solve(n, s):
	c = 0
	for i in range(n):
		if s[i] != '0':
			c += int(s[i]) + 1
	if s[-1] != '0':
		c -= 1
	print(c)
for _ in range(int(input())):
	n = int(input())
	s = str(input())[:-1]
	solve(n, s)


import math
modulo = 10 ** 9 + 7
n_tests = int(input())
for test in range(n_tests):
	n = int(input())
	s = input()
	sint = [int(x) for x in s]
	sum = 0
	nzerodigs = 0
	for i in sint:
		sum += i
		if i != 0:
			nzerodigs += 1
	if sum == 0:
		print(0)
	elif s[-1] != '0':
		print(sum + nzerodigs - 1)
	else:
		print(sum + nzerodigs)


def main():
	m = 0
	n = int(input())
	s = input()
	for i in range(n):
		if s[i] != '0':
			m += int(s[i])
			if i != n - 1:
				m += 1
	print(m)
t = int(input())
for i in range(t):
	main()


T = int(input())
while T:
	n = int(input())
	x = input()
	s = 0
	for i in range(n):
		if x[i] != '0':
			if i == n - 1:
				s += int(x[i])
			else:
				s += int(x[i]) + 1
	print(s)
	T -= 1


from sys import stdin, stdout
from io import StringIO

def main(inbuf, outbuf):
	t = int(inbuf.readline())
	for _ in range(t):
		n = int(inbuf.readline())
		s = [int(x) for x in inbuf.readline().strip()]
		ans = sum(s) + sum((bool(x) for x in s[:-1]))
		outbuf.write(str(ans) + '\n')
outbuf = StringIO()
main(stdin, outbuf)
print(outbuf.getvalue(), file=stdout, end='')


k = int(input())
for i in range(k):
	n = int(input())
	s = list(map(int, input()))
	total = sum(s)
	a = n - s.count(0)
	b = s[-1] > 0
	ans = total + a - b
	print(ans)


t = int(input())
for i in range(t):
	count = 0
	n = int(input())
	s = input()
	sum_listed = sum([int(s[i]) for i in range(len(s))])
	non_zero = len(s) - s.count('0')
	count = non_zero + sum_listed - 1 if s[-1] != '0' else non_zero + sum_listed
	print(count)


test = int(input())
for _ in range(test):
	n = int(input())
	time = input()
	res = 0
	for i in range(n):
		if int(time[i]) > 0:
			res += int(time[i])
			if i != n - 1:
				res += 1
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in list(input())]
	count = 0
	for (i, e) in enumerate(arr):
		if e:
			count += e + 1
			if i == n - 1:
				count -= 1
	print(count)


def zam(q, t):
	s = 0
	for i in range(t):
		if q[i] != '0':
			if i != t - 1:
				s += int(q[i]) + 1
			else:
				s += int(q[i])
	return s
c = int(input())
for i in range(c):
	t = int(input())
	q = input()
	print(zam(q, t))


t = int(input())
for j in range(t):
	sum = 0
	count = 0
	c = input()
	b = input()
	a = list(b)
	for i in a:
		i = int(i)
		sum += i
		if i > 0:
			count += 1
	if a[-1] == '0':
		print(count + sum)
	else:
		print(count + sum - 1)


for _ in range(int(input())):
	length = int(input())
	array = input()
	count = 0
	for i in range(len(array)):
		if array[i] != '0':
			count += int(array[i]) + 1 if i != len(array) - 1 else int(array[i])
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, list(input())))
	print(sum(l) + sum([x != 0 for x in l]) - int(l[-1] > 0))


for _ in range(int(input())):
	N = int(input())
	S = input()
	C = 0
	for i in range(N - 1):
		if int(S[i]):
			C += int(S[i]) + 1
	print(C + int(S[N - 1]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	sum = 0
	for i in range(n - 1):
		if a[i] != '0':
			sum += int(a[i]) + 1
	if a[n - 1] != '0':
		sum += int(a[n - 1])
	print(sum)


t = int(input())
while t != 0:
	n = int(input())
	temp = list(input())
	s = list(map(int, temp))
	count = 0
	total = 0
	for i in s:
		if i > 0:
			count += 1
			total += i
	ans = total + (count - 1)
	if s[-1] == 0:
		ans += 1
	print(ans)
	t -= 1