  /* package codechef; // don't place package name! */

 import java.util.*;
 public class f{
    public static void main(String[] ta){
   Scanner sc =new Scanner(System.in) ;
 if(sc.hasNext()){
 int t =sc.nextInt();
while(t-->0){
int a = sc.nextInt();
int b = sc.nextInt();
int c =0;
int total=0;
String s = "a";
while(a>0)
{
   c =a%10;
  a /=10;
   c += b;
   s = Integer.toString(c);
   c = s.length() ;
   c = c% 1000000007;
  total += c;}
System.out.println(total%1000000007);}}}}
