import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String[] args) throws IOException{
	 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	 int t=Integer.parseInt(br.readLine());
	 while(t>0){
	     String []s =br.readLine().split(" ");
	     int n=Integer.parseInt(s[0]);
	     int k=Integer.parseInt(s[1]);
	     String h=s[0];
	     int y=0;
	     for(int i=0;i<h.length();i++){
	         char q=h.charAt(i);
	         int j=Character.getNumericValue(q); 
	         if(j+k>=10) y++;
	     }
	     int g=h.length()+y;
	     System.out.println(g);
	     
	     
	     t--;
	 }
	  
	}
}
