import java.util.*;
public class Add {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int tt = 0; tt < t; tt++) {
            int n = sc.nextInt();
            int o = sc.nextInt();
            int copy, count = 0, length = 0;
            while(n > 0) {
                int mod = n % 10;
                for(int i = 0; i < o; i++) {
                    mod += 1;
                }
                length += Integer.toString(mod).length();
                n /= 10;
            }
            System.out.println(length);
        }
        sc.close();
    }
}