description: 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 ≤ t ≤ 10^3).
  
  The first line of each test case contains a single integer n (1 ≤ n ≤ 100) — number of digits on the clock.
  
  The second line of each test case contains a string of n digits s_1, s_2, …, s_n (0 ≤ s_1, s_2, …, s_n ≤ 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.
  
  Example
  
  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.
solution: import java.util.*;
  import java.io.*;
  import java.lang.*;
  
  
  public class cf743 {
  //HashSet<Integer> hs=new HashSet<>();
  //PriorityQueue<Integer> pq=new PriorityQueue<>();
  //HashMap<Integer,Integer> hm=new HashMap<>();
  //ArrayList<Integer> lt=new ArrayList<>();
      static long mod=1000_000_007;
  
      public static void solve1() throws Exception{
          InputStreamReader ip=new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(ip);
          int t = Integer.parseInt(br.readLine());
          StringBuilder asb=new StringBuilder();
  		
         while(t-->0){
          int n =Integer.parseInt(br.readLine());
          // String[] strs=(br.readLine()).trim().split(" ");
          // int n=Integer.parseInt(strs[0]),k=Integer.parseInt(strs[1]),r=Integer.parseInt(strs[2]),s=Integer.parseInt(strs[3]);
           String str=(br.readLine()).trim();
          // int[] arr=new int[n];
          // for(int i=0;i<n;i++){arr[i]=Integer.parseInt(strs[i]);}
              long op=0;
              if(n>=1){
                  int ct0=0;
                  for(int i=0;i<n;i++){
                      char ch=str.charAt(i);  String nb=ch+"";
                      op+=Integer.parseInt(nb);
                      if(ch=='0' && i<n-1){ ct0++; }
                  }
                  op+=((n-1)-ct0);
                  // if(str.charAt(n-2)!='0'){ op+=1; }  
                  // if(op>1)op--;
              }
              // else{
              //     if(n==1 || n==2){
              //         op=Integer.parseInt(str);
              //     }else if(n==3){
              //         op=Integer.parseInt(str.charAt(1)+"0");
              //         op+=Integer.parseInt(str.charAt(2)+"");
              //         char c1=str.charAt(0);
              //         if(c1!='0'){
              //             op+=Integer.parseInt(c1+"");  op++;
              //         }
              //     }
              // }
  
              // asb.append(op+"    "+str+"   "+"\n");
              asb.append(op+"\n");
           }
  
           System.out.println(asb);
      }
     
  
      public static void solve3() throws Exception{
          InputStreamReader ip=new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(ip);
          int t = Integer.parseInt(br.readLine());
          StringBuilder asb=new StringBuilder();
  		
         while(t-->0){
          int n =Integer.parseInt(br.readLine());
          String[] strs=(br.readLine()).trim().split(" ");
          // int n=Integer.parseInt(strs[0]),k=Integer.parseInt(strs[1]),r=Integer.parseInt(strs[2]),s=Integer.parseInt(strs[3]);
          //  String str=(br.readLine()).trim();
          int[] arr1=new int[n];
          int[] arr2=new int[n];
          for(int i=0;i<n;i++){arr1[i]=Integer.parseInt(strs[i]);}
          
          strs=(br.readLine()).trim().split(" ");
          
          for(int i=0;i<n;i++){arr2[i]=Integer.parseInt(strs[i]);}
          
  
          int i=0,j=0;
          int sw=2*n;
  
          while(i<n && j<n){
              while(i<n && (i+j)<sw){
                  if(arr1[i]<arr2[j]){
                      sw=Math.min(sw, (i+j));  break;
                  }
                  i++;
              }
              i=0;
  
              j++;
  
              if(j>=sw)break;
          }
  
          asb.append(sw+"\n");
  
  
           }
  
           System.out.println(asb);
  
      }
  
     
  //******************************************************************************************************************** */
      public static void main(String[] args) throws Exception{
          solve1();
      }
  
       public static void solve2() throws Exception{
          InputStreamReader ip=new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(ip);
          int t = Integer.parseInt(br.readLine());
          StringBuilder asb=new StringBuilder();
  		
         while(t-->0){
          // int n =Integer.parseInt(br.readLine());
          // String[] strs=(br.readLine()).trim().split(" ");
          // int n=Integer.parseInt(strs[0]),k=Integer.parseInt(strs[1]),r=Integer.parseInt(strs[2]),s=Integer.parseInt(strs[3]);
          //  String str=(br.readLine()).trim();
          // int[] arr=new int[n];
          // for(int i=0;i<n;i++){arr[i]=Integer.parseInt(strs[i]);}
           }
      }
     
  //******************************************************************************************************************** */
  
      public static long modInverse1(long a, long m){
          // int g = gcd(a, m);
          // if(g!=1) {System.out.println("Inverse Doesnot Exist");}  
          return binexp(a, m - 2, m);
         }
     
      public  static long binexp(long a, long b, long m){
          if (b == 0)return 1; 
              
          long res = binexp(a, b / 2, m);
          if (b % 2 == 1) return (( (res*res)%m )*a) % m;
          else return (res*res)%m;
      }
  
      //binexp
      public static long binexp(long a,long b){
          if(b==0)return 1;
  
          long res=binexp(a, b/2);
  
          if(b%2==1){
              return (((res*res))*a);
          }else return (res*res);
      }
  
      //Comparator Interface
      public static class comp implements Comparator<int[]>{
          public int compare(int[] a,int[] b){
              return a[0]-b[0];
          }
      }
  
  	//gcd using Euclid's Division Algorithm  
      public static long gcd(long a,long b){   
          if(b==0)return a;
          else return gcd(b, a%b);
      }
  
  	//check prime in root(n)
      public static int isprime(int n){
          for(int i=2;i<=Math.sqrt(n);i++){
              if(n%i==0)return i;
          }
  
          return -1;   //means n is prime
      }
  
  	//SOE
  	static  int[] sieve;
  	public static void SOE(int n){
          sieve=new int[n+1];
  
          // System.out.println("All prime number from 1 to n:-");
          
          for(int x=2;x<=n;x++){
              if(sieve[x]!=0){  //Not prime number
                  continue;
              }
              // System.out.print(x+"  ");
              for(int u=2*x;u<=n;u+=x){
                  sieve[u]=x;
              }
          }
  
  		//If  sieve[i]=0 means 'i' is primr else 'i' is not prime 
      }
  
      //sort
       public static void sort(long[] arr) {
  		int n = arr.length;
  		for (int i = 0; i < n; i++) {
  			int idx = (int) Math.random() * n;
  			long temp = arr[i];  arr[i] = arr[idx];  arr[idx] = temp;  //swap
  		}
  		Arrays.sort(arr);
  	}
   
  	public static void sort(int[] arr) {
  		int n = arr.length;
  		for (int i = 0; i < n; i++) {
  			int idx = (int) Math.random() * n;
  			int temp = arr[i];  arr[i] = arr[idx]; arr[idx] = temp;  //swap
  		}
  		Arrays.sort(arr);
  	}
      //1d print
      public static void print(int[] dp) {
  		for (int val : dp) {
  			System.out.print(val + " ");
  		}
  		System.out.println();
  	}
   
  	public static void print(long[] dp) {//Method Overloading
  		for (long val : dp) {
  			System.out.print(val + " ");
  		}
  		System.out.println();
  	}  
      //2d print
  	public static void print(long[][] dp) {//Method Overloading
  		for (long[] a : dp) {
  			for (long val : a) {
  				System.out.print(val + " ");
  			}
  			System.out.println();
  		}
  	}
   
  	public static void print(int[][] dp) {
  		for (int[] a : dp) {
  			for (int val : a) {
  				System.out.print(val + " ");
  			}
  			System.out.println();
  		}
  	}
   
  	
  }