import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		for (int i = 0; i < N; i++) {
			int n = scanner.nextInt();
			String nString = n + "";
			int k = scanner.nextInt();
			int ans = 0;
			int len = 1;
			int count = 0;
			int last = 0;

			for (int j = 0; j < nString.length(); j++) {
				len = 2;
				count = 0;
				int temp = k;
				int p = nString.charAt(j) - '0';
				int diff = 10 - p;
				temp -= diff;
				if (temp < 0) {
					ans += 1;
					continue;
				}
				count = temp / 10;
				last = temp % 10;
				int q = count % 10;
				int d = 10 - q;
				boolean flag = false;
				if (temp >= 90) {
					flag = true;
					for (int o = 1; o <= 9; o++) {
						len *= 2;
						count--;
					}
				} else {
					while (count > 0) {
						len *= 2;
						count--;
					}
				}
				if (flag) {
					ans += (len + 1  + (temp - 90) * 9);
				} else {
					if (last < d) {
						ans += len;
					} else {
						if (last == d) {
							ans += len + 1;
						} else if (last - d < 9 - d) {
							ans += len + 1 + q * (last - d);
						} else {
							ans += len + 1 + q * (8 - d) + d;
						}
					}
				}
			}
			System.out.println((int)(ans % (Math.pow(10, 9) + 7)));

		}
		scanner.close();
	}
}
	  	 	  		  	  			 			 	    	 	