import sys
input=sys.stdin.readline
t=int(input())
MOD=10**9+7
q=2*10**5+1
dp=[0]*(100*q)
 
for i in range(10):
  s=i*q*10
  dp[s+i*q]=1
  for k in range(2*10**5):
    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
    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
dp2=[0]*(10*q)
for i in range(10):
  for k in range(2*10**5):
    r=0
    for j in range(10):
      r=(r+dp[i*q*10+j*q+k])%MOD
    dp2[i*q+k]=r%MOD
for _ in range(t):
  s,r=map(int,input().split())
  s=str(s)
  count=[0]*10
  for i in range(len(s)):
    count[int(s[i])]+=1
  ans=0
  for i in range(10):
    ans=(dp2[i*q+r]*count[i])%MOD
  print(ans)
