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

public class C1513 {
	public static void main(String args[]) throws Exception {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();

		while (t-- > 0) {
			long n = in.nextInt();
			int d = in.nextInt(), count = 0;

			while (n > 0) {
				if (((n % 10) + d) > 99999) count += 6;
				else if (((n % 10) + d) > 9999) count += 5;
				else if (((n % 10) + d) > 999) count += 4;
				else if (((n % 10) + d) > 99) count += 3;
				else if (((n % 10) + d) > 9) count += 2;
				else count++;
				n /= 10;
			}
			System.out.println(count % 1000000007);
		}
	}
}