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

import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastReader sc = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int t = sc.nextInt();
		while(t-->0)
		{
		    int n = sc.nextInt();
		    int m = sc.nextInt();
		    long digits=0;
		    long mod=(long)Math.pow(10,9)+7;
		    //int calcSize=n;
		    //while(calcSize!=0) {calcSize=calcSize/10;digits++;}
		    while(n!=0)
		    {
		        int curr = n%10;
		        int ops=m;
		        long currDigits=2;
		        ops=ops-(10-curr);
		        if(ops<0) {digits=(digits+1)%mod;n=n/10;continue;}
		        //if(ops>=0)currDigits*=2;
		        
		        //ops=ops/10;
		        long ans=(2*itrPower(2,ops/10,mod))%mod;
		        if(ops%10==9) ans=(ans*2)%mod-1;
		        digits=(digits+(ans)%mod)%mod;
		        n=n/10;
		    }
		    System.out.println(digits);
		}
		
		
		out.close();
	}
	static long itrPower(int a,int n,long mod)
	{
	    if(a==0) return 0;
	    if(n==0) return 1;
	    long temp=a,ans=1;
	    for(int i=0;i<32;i++)
	    {
	        if((n&1)==1)
	        {
	            ans=((ans%mod)*(temp%mod));
	        }
	        n=n>>1;
	        temp=(temp*temp)%mod;
	    }
	    return ans;
	}
}

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
 
    public FastReader() 
    { 
        br = new BufferedReader(new
                 InputStreamReader(System.in)); 
    } 
 
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
 
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
 
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
 
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
 
    String nextLine() 
    { 
        String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}