import java.util.*;

public class Solution
{
	public static void main (String[] args)
	{
	   // BufferedReader br = new BufferedReader( new InputStreamReader(System.in ) );
	    Scanner s = new Scanner(System.in);
	    int t = Integer.parseInt( s.nextLine() );
	    
	    while(t-->0)
	    {
	        String parts[] = s.nextLine().split( " ");
	        String n = parts[0];
	        int m = Integer.parseInt( parts[1] );
	        
	        int arr[] = new int[10];
	        for(int i=0; i<n.length(); ++i )
	        {
	            char ch = n.charAt( i );
	            
	            int num = ch-'0';
	            
	            arr[num]++;
	        }
	        
	        long total=0;
	        long mod = 1000000007;
	        
	        for(int i=0; i<arr.length; ++i)
	        {
	            if(arr[i]>0)
	            {
	                long len=1;
    	            if( 100000-i <= m )
    	            {
    	                len = (len +5)%mod;
    	            }
    	            else if( 10000-i <= m )
    	            {
    	                len = (len +4)%mod;
    	            }
    	            else if( 1000-i <= m )
    	            {
    	                len = (len +3)%mod;
    	            }
    	            else if( 100-i <= m )
    	            {
    	                len = (len +2)%mod;
    	            }
    	            else if( 10-i <= m )
    	            {
    	                len = (len +1)%mod;
    	            }
    	            
	                len = (len * arr[i])%mod;
	                
	                total = ( total+len )%mod;
	                
	               // System.out.println( i + " "+ total );
	            }
	        }
	        System.out.println(total);
	    }
	}
}
