import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C implements Runnable {

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

		new Thread(null, new C(), "SwapnilGanguly", 1 << 26).start();
	}

	MyScanner sc = new MyScanner();
	PrintWriter pr = new PrintWriter(System.out);

	public void run() {

		int T = sc.nextInt();

		while (T-- > 0) {

			String s = sc.next();
			int moves = sc.nextInt();
			int[] freq = new int[10];
			long mod = (long) (1e9 + 7);

			for (int i = 0; i < s.length(); i++)
				freq[s.charAt(i) - '0']++;

			long ans = s.length();

			while (moves > 0) {

				int max = findMax(freq);

				if (moves != 1 && moves >= 9 - max) {

					int temp[] = new int[10];

					for (int i = 0; i <= max; i++) {

						if (freq[i] > 0)
							temp[i + 9 - max] += freq[i];
					}

					for (int i = 0; i < 10; i++)
						freq[i] = temp[i];

					moves -= 9 - max;
				}

				int temp[] = new int[10];

				for (int j = 0; j < 9; j++) {

					if (freq[j] > 0)
						temp[j + 1] = freq[j];
				}

				if (freq[9] > 0) {

					ans = (ans + freq[9]) % mod;
					temp[0] += freq[9];
					temp[1] += freq[9];
				}

				for (int j = 0; j < 10; j++)
					freq[j] = temp[j];

				moves--;
			}
			pr.println(ans);
		}
		pr.close();
	}

	private void print(int[] freq) {

		for (int i : freq)
			System.out.print(i + " ");
		System.out.println("\n");

	}

	public int findMax(int[] freq) {

		int max = 0;
		for (int i = 0; i < 10; i++) {

			if (freq[i] > 0)
				max = i;
		}

		return max;
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			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;
		}
	}
}
