t = int(input())
arr = [list(map(int, input().split())) for i in range(t)]

for n, m in arr:
    n = [int(i) for i in str(n)]
    for i in range(len(n)):
        n[i] += m
    ans = 0
    for i in n:
        ans += len(str(i))
    print(ans)
