import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

import static java.lang.System.currentTimeMillis;
import static java.lang.System.in;

public class JCAddOne {
    static class Solver {
        static long modulo = (long) 1e9 + 7;

        static long[] cache = new long[200005];
        static boolean inited = false;

        static void init(){
            if (inited) return;
            for (int i = 0; i <= 8; i++) cache[i] = 2L;
            cache[9] = 3L;
            for (int i = 10; i <= 200004; i++) cache[i] = (cache[i - 9] + cache[i - 10]) % modulo;
            inited = true;
        }

        static Long solve(Long ab, Integer b) {
            init();

            var ints = ab;
            var sum = 0L;
            while (ints > 0) {
                int i = (int) (ints % 10);
                if (b + i - 10 >= 0)
                    sum = sum + cache[b + i - 10] % modulo;
                else
                    sum = sum + 1;
                ints /= 10;
            }
            return sum;
        }
    }

    public static void main(String[] args) throws IOException {
        long start = currentTimeMillis();
        BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
//        BufferedReader file = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(
//        "5\n1912 1\n5 6\n999 1\n88 2\n12 100".getBytes())));
//        "1\n12 100".getBytes())));
        int t = Integer.parseInt(file.readLine());
        Pattern pattern = Pattern.compile(" ");
        var i = 0;
        while (i < t) {
            String[] a = pattern.split(file.readLine());
            System.out.println(Solver.solve(Long.parseLong(a[0]), Integer.parseInt(a[1])));
            i += 1;
        }
        System.out.println(currentTimeMillis() - start);
    }
}