t = int(input())
for case in range(t):
    n,m = input().strip().split()
    m = int(m)
    length = len(n)
    for d in n:
        d = int(d)
        if d+m > 9: 
            length += 1
            s = (m - (10-d)) // 10
            u = 2 ** (s+2) - 1
            print("u",u)
            length += u
    print(length)

        
