from sys import stdin
input=stdin.readline
m=2*(10**5)+15
dp=[1]*m
mod=int(1e9+7)
for i in range(10,m):
    dp[i]=(dp[i-9]+dp[i-10])%m
    


for i in range(int(input())):
    n,m=map(int,input().strip().split())
    ans=0
    while n:
        x=n%10
       
        
        ans=(ans+dp[x+m])
        ans%=mod
        n=n//10
    print(ans)