from math import log10

for _ in range(int(input())):
	data = input().split()
	ini = data[0]
	m = int(data[1])
	result = 0
	for ch in ini:
		result += (int(log10(int(ch) + m)) + 1) % (1e9 + 7)
	print(result % (1e9 + 7))