import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Map.Entry;

import java.util.Random;
import java.util.TreeSet;

public final class CF_714_D2_C
{


	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void logWln(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputFlush(Object o){try {out.write(""+ o+"\n");out.flush();} catch (Exception e) {}}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}


	static void logBin(int[] tm) {for (int x:tm) logWln(bin(8,x)+" ");log("");}

	static String bin(int L,int x) {
		String s=Integer.toBinaryString(x);
		while (s.length()<L) s="0"+s;
		return s;
	}

	static long powerMod(long b,long e,long m){
		long x=1;
		while (e>0) {
			if (e%2==1)
				x=(b*x)%m;
			b=(b*b)%m;
			e=e/2;
		}
		return x; 
	}



	static long mod=1000000007;



	// Global vars
	static BufferedWriter out;
	static InputReader reader;


	static class Composite implements Comparable<Composite>{
		int a;
		int b;
		int idx;

		public int compareTo(Composite X) {
			if (a!=X.a)
				return a-X.a;
			if (b!=X.b)
				return b-X.b;
			return idx-X.idx;
		}

		public Composite(int a, int b, int idx) {
			this.a = a;
			this.b = b;
			this.idx = idx;
		}


	}

	static class Bonx implements Comparable<Bonx>{
		long v;
		int idx;

		public int compareTo(Bonx X) {
			if (v<X.v)
				return -1;
			if (v>X.v)
				return 1;
			return idx-X.idx;
		}

		public Bonx(long v, int idx) {
			this.v = v;
			this.idx = idx;
		}





	}



	static long[][] mult(long[][] A,long[][] B,long mod){
		int M=A.length;
		long[][] res=new long[M][M];
		for (int i=0;i<M;i++)
			for (int j=0;j<M;j++) {
				res[i][j]=0;
				for (int k=0;k<M;k++) {
					res[i][j]+=A[i][k]*B[k][j];
					if (res[i][j]>=mod)
						res[i][j]%=mod;
				}

			}
		return res;
	}

	static long[][] powerMat(long[][] A,int e,long mod){
		long[][] X=null;
		long[][] B=A;
		while (e>0) {
			if (e%2==1) {
				if (X==null) 
					X=B;
				else 
					X=mult(B,X,mod);
			}
			B=mult(B,B,mod);
			e=e/2;
		}
		return X;	
	}


	static long[][] get(long[][][] cache,int pow,long mod){

		long[][] res=null;
		for (int i=0;i<NX;i++) {
			int shift=1<<i;
			if ((shift&pow)!=0) {
				if (res==null)
					res=cache[i];
				else
					res=mult(res,cache[i],mod);
			}
		}
		return res;
	}

	static int NX=20;

	static void process() throws Exception {


		log(Integer.toBinaryString(200001).length());
		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);

		int CX=10;
		long[][] mat=new long[CX][CX];
		for (int i=0;i<9;i++) {
			mat[i+1][i]=1;
		}
		mat[0][9]=1;
		mat[1][9]=1;
		//log("computing cache");
		long[][][] cache=new long[NX][][];
		long[][] ref=new long[CX][CX];
		for (int i=0;i<CX;i++)
			ref[i][i]=1;

		cache[0]=mat;
		for (int i=1;i<NX;i++) {
			cache[i]=powerMat(cache[i-1],2,mod);
		}
		log("done");
		long[][] bob;

		int T=reader.readInt();

		int[] vect=new int[CX];
		for (int t=0;t<T;t++) {
			int n=reader.readInt();
			int m=reader.readInt();

			String s=""+n;
			for (int i=0;i<s.length();i++) {
				int x=s.charAt(i)-'0';
				vect[x]++;
			}
			bob=get(cache,m,mod);
			long sum=0;
			for (int i=0;i<CX;i++)
				for (int j=0;j<CX;j++) {
					sum+=bob[i][j]*vect[j];
					while (sum>=mod)
						sum-=mod;
				}
			output(sum);
		}






		try {
			out.close();
		} catch (Exception Ex) {
		}

	}


	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final String readString(int L) throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder(L);
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}