t=int(input())
while t:
    t-=1
    l=list(map(int,input().split()))
    n=l[0]
    m=l[1]
    d=[int(x) for x in str(n)]
    while m:
        m-=1
        for i in range(len(d)):
            d[i]=d[i]+1

    d1=[str(int) for int in (d)]
    t1="".join(d1)
    print(len(t1))