import java.io.*;
import java.util.*;
public class C{
	public static void main(String[] args){
		PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
		Scanner sc=new Scanner();
		//--------------------------------------------------------------------------
		ArrayList<Double> results=new ArrayList<>();
		ArrayList<Integer> num=new ArrayList<>();
		double length;
		int t, n, m, x, y, temp;

		t=sc.nextInt();
		for(int i=0;i<t;i++){
			n=sc.nextInt();
			m=sc.nextInt();
			num.clear();
			length=0;
			do{
				num.add(n%10);
				n/=10;
			}while(n>0);
			for(int no:num){
				if(m+no>9){
					temp=m-(10-no);
					x=temp/9;
					y=temp/10;
					length=length+x+y+2+((x*(x-1))/2)+((y*(y-1))/2);
				}else{
					length++;
				}
			}
			length=length%(Math.pow(10, 9)+7);
			results.add(length);
		}
		//--------------------------------------------------------------------------
		results.forEach((d)->{
			String str=Double.toString(d);
			str=str.substring(0, str.length()-2);
			out.println(str);
		});
		out.close();
	}
	private static class Scanner{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			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();
		}
		String nextLine(){
			String str="";
			try{
				str=br.readLine();
			}catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
	}
}
