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 long[][] memo2 = new long[20001][10];
    public static int maxFound = 0;
    public static long calculate(int s, int n) {

        boolean found = false;


        for (int i = 0; i < 10; i++) {
            if (memo2[n][i] != 0) {
                found = true;
                break;
            }
        }
        if (found) {
            return memo2[n][s];
        }
        

        long[] nums = new long[10];

        nums[s] = 1;

        for (int i = 0; i < n; i++) {
            long m = 0;
            for (int j = 0; j < 10; j++) {
                if (j == 9) {
                    nums[0] = m;
                    nums[1] += m;
                } else {
                    if (j == 0) {
                        m = nums[j + 1];
                        nums[j + 1] = nums[j];
                    } else {
                        long temp = nums[j + 1];
                        nums[j + 1] = m;
                        m = temp;
                    }
                }
            }
            long total = 0;
            for (int j = 0; j < 10; j++) {
                total += nums[j];
            }
            memo2[i][s] = total;
        }

        //find 0-9;
        return memo2[n][s];

    }

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

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

        for (int i = 0; i < 10; i++) {
            calculate(i, 20000);
        }
        
        for (int i = 0; i < n; i++) {
            int m;
            char[] num;

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

            int ans = 0;
            for (char c : num) {
                ans += memo2[m][c - '0'];
            }
            System.out.println(ans);
        }
    }
}