import java.util.*;
import java.io.*;
 
public class Main2 {
	static 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; } 
    }
	static long mod = (int)(1e9+7);
	static FastReader sc = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static long dp[];
	static char s[];
	public static void main (String[] args) {
		int t = 1;
    	t = sc.nextInt();
		dp = new long[200001];
		Arrays.fill(dp, -1);
		dp[0] = 2;
	    z : while(t-->0) {
    		s = sc.next().toCharArray();
    		int num = sc.nextInt();
    		long count = 0;
    		for(int i=0;i<s.length;i++) {
    			int number  = s[i]-'0';
    			count += solve(num-(10-number))%mod;
    		}
    		out.write(count+"\n");
		}
		out.close();
	}
	private static long solve(int num) {
		if(num<0) return 1;
		if(num == 0) return 2;
		if(dp[num]!=-1) return dp[num]%mod;
		return dp[num] = (solve(num-9)+solve(num-10))%mod;
	}
}