import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')
P = lambda: list(map(int, input().split()))
from math import factorial as f

mod = 10**9+7
dp = [1 for _ in range(200001)]
for i in range(1, 200001):

    if i <= 9:
        dp[i] = 2
    else:
        dp[i] = (dp[i-10] + dp[i-9]) % mod

tc = int(input())
for _ in range(tc):
    n, m = map(int, input().split())
    ans = 0
    while n:
        d = n%10
        n //=10
        
        x = m - (9-d)
        if x <= 0:
            ans += 1
        else:
            ans += dp[x]
    print(ans)



    



              




