import java.io.*;

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 {
        new Thread(null, new Runnable() {
            public void run() {
                try {
//        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())));
                    PrintWriter out = new PrintWriter(System.out);
                    int t = Integer.parseInt(file.readLine());
                    var i = 0;
                    while (i < t) {
                        String[] a = file.readLine().split(" ");
                        out.println(Solver.solve(Long.parseLong(a[0]), Integer.parseInt(a[1])));
                        i += 1;
                    }
//        out.println("time:" + (currentTimeMillis() - start));
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }, "1", 1 << 26).start();
    }
}
