import java.util.*;

public class Test3{
	public static void main(String args[]) {
		String result = "";
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		for(int i=0;i<n;i++) {
			int num = sc.nextInt();
			int times = sc.nextInt();
			result = result+dynamicP(num,times)+"\n";
		}
		System.out.println(result);
	}
	
	public static int dynamicP(int num,int times) {
		String newNum = num+"";
		int arr[] = new int[10];
		int length = 0;
		
		for(int i=0;i<newNum.length();i++) {
			int temp = Integer.parseInt(newNum.charAt(i)+"");
			if(arr[temp] == 0 ) {
				length += getLength(temp,times);
				arr[temp] = length;
				System.out.println("fp");
			}else {
				length += getLength(temp,times);
				System.out.println("dp");
			}
		}
		return length;
	}
	
	public static int getLength(int num,int times) {
		String newNum = num+"";
		
		for(int i=0;i<times;i++) {
		    String temp1 = newNum;
		    String temp2 = "";
		    
		    for(int j=newNum.length()-1;j>=0;j--) {
		        int temp3 = Integer.parseInt(temp1.charAt(j)+"");
		        temp3++;
		        temp2 = temp3+temp2;
		    }
		    newNum = temp2;
		}
		return (int) (newNum.length()%(Math.pow(10, 9)+7));
	}
}
