t=int(input())

for i in range(t):
    lis=[int(i) for i in input().split()]
    s=str(lis[0])
    n=lis[1]
    fin=0
    for i in range(len(s)):
        a=str(int(s[i]) +n )
        fin=len(a)+fin
        
    print(fin)
    