def sum_one(s, m):
    if m == 0:
        return len(s)
    elif int(s) + m < 10:
        return 1
    elif len(s) == 1:
        return sum_one("10", m-10-int(s))
    else:
        aux = "".join([str(int(x) + 1) for x in s])
    return sum(sum_one(x, m-1) for x in aux)

for _ in range(int(input())):
    s, m = input().split()
    print(sum_one(s, int(m)))