import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t=int(input())
MOD=10**9+7
q=2*10**5+1
dp=[0]*(100*q)
dp2=[0]*(10*q)
for i in range(10):
  s=i*q*10
  dp[s+i*q]=1
  for k in range(2*10**5):
    r=0
    for j in range(9):
      dp[s+(j+1)*q+k+1]=(dp[s+(j+1)*q+k+1]+dp[s+j*q+k])%MOD
      r=(r+dp[s+j*q+k])%MOD
    r=(r+dp[s+9*q+k])%MOD
    dp2[i*q+k]=r
    dp[s+k+1]=(dp[s+k+1]+dp[s+9*q+k])%MOD
    dp[s+q+k+1]=(dp[s+q+k+1]+dp[s+9*q+k])%MOD

      
    
for _ in range(t):
  s,r=map(int,input().split())
  count=[0]*10
  while s:
    count[s%10]+=1
    s//=10
  ans=0
  for i in range(10):
    if count[i]:
      ans=(ans+dp2[i*q+r]*count[i])%MOD
  print(ans)
