t = int(input())
k = str()
l = []
p = 0
for i in range(t):
    n,m = map(str,input().split())
    for i in range(int(m)):
        for i in range(len(n)):
            z = int(n[i]) + 1 
            l.append(str(z))
    for i in range(len(l)):
        p += len(l[i])
    print(p)