import sys

input = sys.stdin.readline

MOD = 10 ** 9 + 7


def mul(a, b):
    n = len(a)
    m = len(b)
    l = len(b[0])
    res = [[0] * l for _ in range(n)]
    for i in range(n):
        for j in range(l):
            for k in range(m):
                res[i][j] += a[i][k] * b[k][j] % MOD
                res[i][j] %= MOD
    return res


def identity():
    res = [[0] * 10 for _ in range(10)]
    for d in range(10):
        res[d][d] = 1
    return res


def op():
    res = [[0] * 10 for _ in range(10)]
    for d in range(1, 10):
        res[d][d - 1] = 1
    res[0][9] = res[1][9] = 1
    return res


def gen(m):
    res = [[0] * 10 for _ in range(10)]
    for d in range(9):
        res[(d + m) % 10][d] = 1
    res[(m - 1) % 10][9] = res[m % 10][9] = 1
    return res


def power(a, b):
    res = identity()
    while b > 0:
        if b % 2 == 1:
            res = mul(res, a)
        a = mul(a, a)
        b //= 2
    return res


MAXM = 200009
count = [1] + [0] * 9
count_sum = [sum(count)]
for i in range(1, MAXM + 1):
    new_count = [0] * 10
    for d in range(1, 10):
        new_count[d] = count[d - 1]
    new_count[0] = count[9]
    new_count[1] += count[9]
    if new_count[1] >= MOD:
        new_count[1] -= MOD
    count = new_count
    count_sum.append(sum(count))


def solve(n, m):
    res = 0
    while n > 0:
        res += count_sum[m + n % 10]
        n //= 10
    return res


res = []
t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    res.append(solve(n, m))
print('\n'.join(map(str, res)))