import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Scanner;

public class addOne {
    public static Dictionary<String, String> memo = new Hashtable<>();
    public static String calculate(String s) {
        if (memo.get(s) != null) {
            return memo.get(s);
        }

        if (s.charAt(0) - '9' != 0) {
            String ret = (s.charAt(0) + 1) + s.substring(1);
            memo.put(s, ret);
            return ret;
        } else {
            String ret = ("10" + s.substring(1));
            memo.put(s, ret);
            return ("10" + s.substring(1));
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = Integer.parseInt(scanner.nextLine());

        for (int i = 0; i < n; i++) {
            int num, m;

            String[] dataIn = scanner.nextLine().split(" ");
            num = Integer.parseInt(dataIn[0]);
            m = Integer.parseInt(dataIn[1]);

            String prev = String.valueOf(num);
            for (int j = 0; j < m; j++) {
                prev = calculate(prev);
            }
            System.out.println(prev.length());
        }

    }
}
