def action(n):
	digits = [int(x)+1 for x in str(n)]

	n1 = ''
	for k in range(len(digits)):
		n1 = n1 + str(digits[k])

	return int(n1), len(digits)

T = int(input())

for i in range(T):
	n , m = map(int, input().split())

	for j in range(m):
		n, l = action(n)

	print(l)
