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

        double[] nums = new double[10];

        nums[s] = 1;

        for (int i = 0; i < n; i++) {
            double 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 {
                        double temp = nums[j + 1];
                        nums[j + 1] = m;
                        m = temp;
                    }
                }
            }
            double total = 0;
            for (int j = 0; j < 10; j++) {
                total += nums[j];
                total %= 1000000007;
            }
            memo2[i][s] = total;
        }

        //find 0-9;

    }

    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;
            double num;

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

            double ans = 0;
            while (num>1) {
                int c = (int) (num % 10);
                num /= 10;
                ans += memo2[Integer.parseInt(dataIn[1])-1][(int) c];
                ans %= 1000000007;
            }
            System.out.printf("%.0f", ans);
        }
    }
}