import java.io.*;
import java.util.*;

public class n714C {

    static long mod = (long)Math.pow(10, 9) + 7;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int t = sc.ni();
        while (t-- > 0) {
            char[] num = sc.next().toCharArray();
            int m = sc.ni();

            int[] count = new int[10];
            int[] len = new int[10];
            for (int i = 0; i < num.length; i++)
                count[num[i] - '0']++;

            long result = 0;
            for (int i = 0; i < 10; i++) {
                if (count[i] == 0)
                    continue;
                len[i] = count(m, i);

                System.out.println(len[i]);
                result = (result + (count[i] * len[i]) % mod) % mod;
            }
            System.out.println(result);

        }
    }

    public static int count (int m, int n) {
        int tmp = m + n;
        if (tmp > 9) {
            return count(tmp - 10, 1) + count(tmp - 10, 0);
        }
        return 1;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in), 32768);
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int ni() {
            return Integer.parseInt(next());
        }

        int[][] graph(int N, int[][] edges) {
            int[][] graph = new int[N][];
            int[] sz = new int[N];
            for (int[] e : edges) {
                sz[e[0]] += 1;
                sz[e[1]] += 1;
            }
            for (int i = 0; i < N; i++) {
                graph[i] = new int[sz[i]];
            }
            int[] cur = new int[N];
            for (int[] e : edges) {
                graph[e[0]][cur[e[0]]] = e[1];
                graph[e[1]][cur[e[1]]] = e[0];
                cur[e[0]] += 1;
                cur[e[1]] += 1;
            }
            return graph;
        }

        int[] intArray(int N, int mod) {
            int[] ret = new int[N];
            for (int i = 0; i < N; i++)
                ret[i] = ni() + mod;
            return ret;
        }

        long nl() {
            return Long.parseLong(next());
        }

        long[] longArray(int N, long mod) {
            long[] ret = new long[N];
            for (int i = 0; i < N; i++)
                ret[i] = nl() + mod;
            return ret;
        }

        double nd() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}
