for _ in range(int(input())):
    n,m = map(int,input().split())
    n = list(str(n))
    while m:
        n=list(map(lambda x: str(int(x)+1), n))
        m-=1
        #print(n)
    print(len(''.join(n)))



