f=int(input())
for _ in range(f):
    nm=input().split()
    n=str(nm[0])
    m=int(nm[1])
    stack=[]
    for i in range(len(n)):
        stack.append(n[i])
    #print(stack)

    for _ in range(m):
        stack=[int(i)+1 for i in stack]
    #print(stack)
    s=''  
    for d in stack:
        s=s+str(d)
    #print(s)
    print(len(s))