import java.util.*;

public class Sol{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0; i<t; i++){
            int n = sc.nextInt();
            int m = sc.nextInt();
            
            
            for(int j=0; j<m; j++){
                int count=0;
                int num=0;
                int b = Integer.toString(n).length();
                //System.out.println("b ="+b);
                for(int k=0; k<b; k++){
                
                    num = num + ((n%10)+1)*(int)Math.pow(10,count);
                    n=n/10;
                    count = Integer.toString(num).length();
                }
                n=num;
                //System.out.println("n=" + n + " j = " +j);
            }
            int b = Integer.toString(n).length();
            System.out.println(b);
        }
    }
}