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

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in, 1 << 14);
        int testNo = in.nextInt();
        for(int i = 0; i < testNo; i++){
            int n = in.nextInt();
            int m = in.nextInt();
            int cardinality = Integer.toString(m).length();
            int distance = (int)Math.pow(10, cardinality) - m;

            long numOps = 0;
            while(n > 0){
                int digit = n % 10;
                if(digit >= distance){
                    numOps += (cardinality + 1);
                }
                else{
                    numOps += cardinality;
                }
                n /= 10;
            }
            System.out.println(numOps%((int)Math.pow(10,9) + 7));
        }

    }

    //Source: QuangIO: https://github.com/quangIO/aps-test-cases/blob/master/Example_fastIO.java
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream, int bufferSize) {
            reader = new BufferedReader(new InputStreamReader(stream), bufferSize);
        }

        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 int nextInt() {
            return Integer.parseInt(next());
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

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