t = int(input())

for l in range(t):
    x = input().split(" ")
    n, m = x[0], x[1]

    l1 = []
    for i in range(int(m)):
         l1 = [str(int(x)+1) for x in n]
         n = ''.join(l1)
         l1 = []
    k = int(n) % 1000000007
    print(len(str(k)))

