There is a street with $$$n$$$ houses in a line, numbered from $$$1$$$ to $$$n$$$. The house $$$i$$$ is initially painted in color $$$c_i$$$. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street beautiful. Tom's painting capacity is defined by an integer, let's call it $$$k$$$.On one day, Tom can do the following repainting process that consists of two steps:   He chooses two integers $$$l$$$ and $$$r$$$ such that $$$ 1 \le l \le r \le n $$$ and $$$ r - l + 1 = k $$$.  For each house $$$i$$$ such that $$$l \le i \le r$$$, he can either repaint it with any color he wants, or ignore it and let it keep its current color. Note that in the same day Tom can use different colors to repaint different houses.Tom wants to know the minimum number of days needed to repaint the street so that it becomes beautiful.

The first line of input contains a single integer $$$t$$$ ($$$ 1 \le t \le 10^4$$$), the number of test cases. Description of test cases follows. In the first line of a test case description there are two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$). The second line contains $$$n$$$ space-separated integers. The $$$i$$$-th of these integers represents $$$c_i$$$ ($$$1 \le c_i \le 100$$$), the color which house $$$i$$$ is initially painted in. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Print $$$t$$$ lines, each with one integer: the minimum number of days Tom needs to make the street beautiful for each test case.

NoteIn the first test case Tom should paint houses 1 and 2 in the first day in color 2, houses 5 and 6 in the second day in color 2, and the last house in color 2 on the third day.In the second test case Tom can, for example, spend 6 days to paint houses 1, 2, 4, 5, 6, 7 in color 3.In the third test case Tom can paint the first house in the first day and houses 6, 7, and 8 in the second day in color 3.

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		c := ReadInts(n)
		println(solve(n, k, c))
	}
}

const Inf = 1 << 29

func solve(n, k int, c []int) int {
	ans := Inf
	for t := 1; t <= 100; t++ {
		i := 0
		cnt := 0
		for i < n {
			if c[i] != t {
				cnt++
				i += k
			} else {
				i++
			}
		}
		ans = Min(ans, cnt)
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

/*
URL:
https://codeforces.com/contest/1457/problem/B
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	t int

	n, k int
	C    []int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n, k = readi2()
		C = readis(n)

		solve()
	}
}

func solve() {
	ans := INF_B30

	for c := 1; c <= 100; c++ {
		// A := make([]int, len(C))
		// copy(A, C)

		res := 0

		i := 0
		for i < n {
			if C[i] == c {
				i++
				continue
			}

			// k個塗りつぶす
			res++
			i += k
		}

		chmin(&ans, res)
	}

	printf("%d\n", ans)
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var t, n, k int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		c := make([]int, n)
		colorMap := make([]int, 100)
		colorResult := make([]int, 100)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &c[i])
			c[i]--
			colorMap[c[i]]++
		}
		for color := range colorMap {
			if colorMap[color] == 0 {
				continue
			}
			for i := 0; i < n; {
				if c[i] == color {
					i++
				} else {
					i += k
					colorResult[color]++
				}
			}
		}

		sort.Ints(colorResult)
		min := colorResult[99]
		for i := range colorResult {
			if colorResult[i] != 0 && colorResult[i] < min {
				min = colorResult[i]
			}
		}
		fmt.Println(min)
	}
}


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$$$.

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.

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

NoteIn 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.

package main

import "fmt"

func solve() int {

	var n int
	fmt.Scanf("%d\n", &n)

	count := 0

	var s string
	fmt.Scanf("%s\n", &s)

	for _, ch := range s {
		if ch != '0' {
			var x int = int(ch) - '0'
			count += x + 1
		}
	}

	if s[n-1] != '0' {
		count--
	}

	return count
}

func main() {

	var t int
	fmt.Scanf("%d\n", &t)

	for t>0 {
		count := solve()
		fmt.Println(count)
		t--
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var dNum int64
		var str string
		fmt.Fscan(r,&dNum)
		fmt.Fscan(r,&str)
		res:=int64(str[len(str)-1]-'0')
		for j:=int64(len(str))-2;j>=0;j--{
			if str[j]!='0'{
				res+=int64(str[j]-'0'+1)
				//fmt.Println(j, str[j], str[j]-'0', str[j]-'0'+1, res)
			}
		}
		fmt.Println(res)
	}
}

/* Author: likely
 * Time: 2021-09-22 22:27:45
**/
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main(){
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t,n,i,ii,su int
	var sr string
	fmt.Fscan(in,&t);
	for ii=1;ii<=t;ii++{
		fmt.Fscan(in,&n)
		fmt.Fscan(in,&sr)
		su=0
		for i=0;i<=n-1;i++{
			if sr[i]!='0'{
				su+=(int)(sr[i])-(int)('0')
				if i!=n-1{
					su++
				}
			}
		}
		fmt.Fprintln(out,su)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var word string
		fmt.Fscan(in,&word)
		list:= make([]int,n)
		tally:=0
		if string(word[n-1]) == "0" {
			tally=0
		} else {
			tally=-1
		}
		for j:=0;j<n;j++{
			x,_:=strconv.Atoi(string(word[j]))
			if x == 0 {
				x=10
			}
			list[j]=x
			if x != 10 {
				tally+=(x+1)
			}
		}
		fmt.Fprintln(out,tally)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1573A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1573A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1573A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1573A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1573A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1573A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1573A
Date: 30/01/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1573/A
Problem: CF1573A
**/
func (in *CF1573A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		ans := 0
		for i := 0; i < n; i++ {
			if str[i]-'0' > 0 {
				ans += int(str[i] - '0')
				if i+1 < n {
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

func NewCF1573A(r *bufio.Reader) *CF1573A {
	return &CF1573A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1573A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, s := 0, 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &s)
		swap, tot := int64(0), int64(0)
		for j := 0; j < n; j++ {
			p, _ := strconv.Atoi(string(s[j]))
			if p > 0 {
				tot, swap = tot+int64(p), swap+1
				if j == n-1 {
					swap--
				}
			}
		}
		fmt.Fprintln(w, tot+swap)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
	s      string
)

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &s)
		var r int
		for i := range s {
			if s[i] != '0' {
				r += int(s[i] - '0')
				if i != n-1 {
					r++
				}
			}
		}
		fmt.Println(r)
	}
}

package main

import "fmt"

func main() {
	var t, n int
	var s string

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		fmt.Scanln(&s)

		r := 0
		for i := 0; i < n-1; i++ {
			if s[i] > '0' {
				r += int(s[i]-'0') + 1
			}
		}
		r += int(s[n-1] - '0')
		fmt.Println(r)
	}
	return
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func Problem1573A(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	t := 0
	fmt.Fscanln(in, &t)
	for tcNo := 1; tcNo <= t; tcNo++ {
		n := 0
		fmt.Fscanln(in, &n)

		s := ""
		fmt.Fscanln(in, &s)

		ops := 0
		for i, r := range s {
			if r == '0' {
				continue
			}
			ops = ops + int(r-'0')
			if i < len(s)-1 {
				ops++
			}
		}
		fmt.Fprintln(out, ops)
	}
}

func main() {
	Problem1573A(os.Stdin, os.Stdout)
}

// template for codeforces problems in format:
// input:
// - number of tests (gotNumberOfTests = true!) - optional
// - tests: one or more lines per test (inputLinesPerTest)
//          with one or more integers on each line, separated by intSeparator
// output:
// - one line per solution, with one or more integers
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var numTests int // number of tests

const (
	gotNumberOfTests  bool = true // first line holds number of tests
	inputLinesPerTest      = 2
	intSeparator           = " "
)

func getInts(s string) (out []int, err error) {
	for _, a := range strings.Split(s, intSeparator) {
		var i int
		i, err = strconv.Atoi(a)
		if err != nil {
			break
		}
		out = append(out, i)
	}
	return
}

func getDigit(b rune) (int, error) {
	return strconv.Atoi(string(b))
}

func main() {
	s := bufio.NewScanner(os.Stdin)

	if gotNumberOfTests {
		s.Scan()
		if i, err := getInts(s.Text()); len(i) != 1 || err != nil {
			fmt.Println("can't process first line")
			return
		} else {
			numTests = i[0]
		}
	}

	for t := 0; ; t++ {
		// process 1 input (one or more lines)
		in := []string{}
		i := 0
		for ; i < inputLinesPerTest && s.Scan(); i++ {
			in = append(in, s.Text())
		}
		if i != inputLinesPerTest {
			// Scan() failed, probably EOF - add check?
			break
		}

		// print output, go routine?
		if len(in) != inputLinesPerTest {
			panic(fmt.Sprintf("expected %d lines per input, got %d", inputLinesPerTest, len(in)))
		}
		for _, o := range solution(in) {
			fmt.Println(o)
		}
	}
}

func solution(in []string) (out []string) {
	s := in[1]

	i := 0
	for _, b := range s[:len(s)-1] {
		if b != '0' {
			i++
		}
	}
	for _, b := range s {
		d, _ := getDigit(b)
		i += d
	}

	out = append(out, fmt.Sprintf("%d", i))

	return
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func main() {
	var t int
	scanf("%d\n", &t)
	s := make([]byte, 103)
	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		scanf("%s\n", &s)

		ans := 0
		for i := n - 1; i >= 0; i-- {
			d := int(s[i] - '0')
			if d != 0 {
				if i != n-1 {
					ans++
				}
				ans += d
			}
		}
		printf("%d\n", ans)
	}
	writer.Flush()
}

package main
import (
	"fmt"
	"bufio"
	"os"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func main(){
	defer writer.Flush()
	var t int
	scanf("%d\n",&t)

	for t>0{
		var (
			n,ans int
		)

		scanf("%d\n",&n)
		var s string
		scanf("%s\n",&s)

		for i:=0;i<len(s)-1;i++{
			if s[i]!=48{
				ans+=int(s[i])-48+1
			}
		}
		if s[len(s)-1]!=48{
			ans+=int(s[len(s)-1])-48
		}
		printf("%d\n",ans)

		t--
	}

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	var n, ops int
	var s string
	for ; t > 0; t-- {
		fmt.Scan(&n, &s)
		ops = 0
		for index, c := range s {
			ops += int(c - 48)
			if c != '0' && index != n-1 {
				ops++
			}
		}

		fmt.Println(ops)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(s []byte) int64 {
	res := int64(0)
	for _, ch := range s {
		digit := int64(ch - '0')
		if digit > 0 {
			res += digit + 1
		}
	}
	if s[len(s)-1] != '0' {
		res--
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		_, s := stdin.Int(), []byte(stdin.Word())
		fmt.Println(solve(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var dNum int64
		var str string
		fmt.Fscan(r,&dNum)
		fmt.Fscan(r,&str)
		res:=str[len(str)-1]-'0'
		for j:=int64(len(str))-2;j>=0;j--{
			if str[j]!='0'{
				res+=str[j]-'0'+1
			}
		}
		if t < 1000 {
			fmt.Println(res)
		}
		if i > 900 {
			fmt.Println(str)
		}
		//fmt.Println(res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var dNum int64
		var str string
		fmt.Fscan(r,&dNum)
		fmt.Fscan(r,&str)
		res:=str[len(str)-1]-'0'
		for j:=int64(len(str))-2;j>=0;j--{
			if str[j]!='0'{
				res+=str[j]-'0'+1
			}
		}
		fmt.Println(res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var dNum int64
		var str string
		fmt.Fscan(r,&dNum)
		fmt.Fscan(r,&str)
		digit:=str[len(str)-1]-'0'
		for j:=int64(len(str))-2;j>=0;j--{
			if str[j]!='0'{
				digit+=str[j]-'0'+1
			}
		}
		fmt.Println(digit)
	}
}