import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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();
            for (int i = 0; i < m; i++) {
                s = process(s);
            }
            out.println(s.length());
        }

        private String process(String s) {
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == '9') {
                    s = s.substring(0, j) + "10" + s.substring(j + 1);
                    j++;
                } else {
                    int c = Character.getNumericValue(s.charAt(j));
                    c++;
                    s = s.substring(0, j) + c + s.substring(j + 1);
                }
            }
            long s_val = Long.parseLong(s);
            s_val = s_val % mod;
            s = s_val + "";
            return s;
        }

    }

    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());
        }

    }
}

