t=int(input())
for i in range(t):
    a,b=map(int,input().split())
    a=str(a)
    if (b>=1) :
        s=""
        for num in a:
            num = int(num)
            num += 1
            s+=str(num)
            a=s
        b=b-1    
    print(len(s))
