

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static long xpown(long x, long n) {
		long res = 1;
		while (n > 0) {
			if (n % 2 != 0) {
				res = (res * x) % 1000000007;
				n--;
			} else {
				x = (x * x) % 1000000007;
				n = n / 2;
			}
		}
		return res % m1;
	}

	static int m1 = 1000000007;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		while (t-- > 0) {

			String[] st = br.readLine().split(" ");
			int n = Integer.parseInt(st[0]);
			int m = Integer.parseInt(st[1]);

			int temp = n;
			int[] arr = new int[10];

			long digit = 0;
			while (temp > 0) {
				int lastval = temp % 10;
				arr[lastval]++;
				temp = temp / 10;
				digit++;
			}

			for (int i = 0; i < arr.length; i++) {
				if (arr[i] == 0 || m < (10 - i)) {
					continue;
				}
				digit -= arr[i];
				int mdash = m;

				int minusop = 10 - i;
				mdash -= minusop;

				int iter = mdash / 9;
				mdash = mdash % 9;

				long pow = xpown(2, iter);

				long ans = (2 * (pow % m1)) % m1;

				long tempdigit = 0;
				tempdigit = ((tempdigit % m1) + (ans % m1)) % m1;

				ans = ans / 2;
				if (mdash == 8) {
					tempdigit = ((tempdigit % m1) + (ans % m1)) % m1;
				}

				tempdigit = ((tempdigit % m1) * (arr[i] % m1)) % m1;
				digit = ((digit % m1) + (tempdigit % m1)) % m1;
			}

			System.out.println(digit);
		}
	}
}
