import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author valeesi
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAddOne solver = new CAddOne();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class CAddOne {
        long mod = 1000000007;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            long m = in.nextLong();
            long result;
            for (int i = 0; i < m; i++) {
                s = process(s);
                if (s.length() > 2000) {
                    BigInteger val = new BigInteger(s);
                    result = val.toString().length() % mod;
                    s = result + "";
                }
            }
            BigInteger val = new BigInteger(s);
            result = val.toString().length() % mod;
            out.println(result);
        }

        private String process(String s) {
            List<Integer> nineIndex = new LinkedList<>();
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == '9') {
                    nineIndex.add(j);
                }
            }
            s = replaceAll(s);
            int inc = 0;
            for (Integer index : nineIndex) {
                s = s.substring(0, index + inc) + '1' + s.substring(index + inc);
                inc++;
            }
            return s;
        }

        private String replaceAll(String s) {
            char[] arr = s.toCharArray();
            for (int i = 0; i < s.length(); i++) {
                if (arr[i] == '9') {
                    arr[i] = '0';
                } else {
                    arr[i] = (char) ((char) arr[i] + 1);
                }
            }
            return Printer.print(arr);

//
//        return s.replaceAll('1', '2')
//                .replaceAll('2', '3')
//                .replaceAll('3', '4')
//                .replaceAll('4', '5')
//                .replaceAll('5', '6')
//                .replaceAll('6', '7')
//                .replaceAll('7', '8')
//                .replaceAll('8', '9')
//                .replaceAll('9', '0')
//                .replace('0', '1');
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Scanner scanner;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            scanner = new Scanner(reader);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }

    static class Printer {
        public static String print(char[] arr) {
            return print(arr, "");
        }

        public static String print(char[] arr, String separator) {
            if (arr == null || arr.length == 0) {
                return "";
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.length; i++) {
                if (i < arr.length - 1) {
                    sb.append(arr[i]).append(separator);
                } else {
                    sb.append(arr[i]);
                }
            }
            return sb.toString();
        }

    }
}

