//package com.company;
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main {
    public static void main (String[] args) throws java.lang.Exception {
        FastReader sc = new FastReader();
        int testCase = sc.nextInt();
        while(testCase-->0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            StringBuilder s = new StringBuilder(String.valueOf(n));
            while (m>0){
                int max = -1;
                int index=0;
                for(int i=0; i<s.length(); i++){
                    if(s.charAt(i)-'0'>max) max = s.charAt(i)-'0';
                }
                if(max==9){
                for(int i=0; ; i++) {
//
                    if (i == s.length()) break;
                    if (s.charAt(i) == '9') {
                        s.delete(i, i + 1);
                        s.insert(i, '1');
                        s.insert(i + 1, '0');
                        i++;
                    } else {
                        s.replace(i, i + 1, String.valueOf(s.charAt(i) - '0' + 1));
                    }
                }
                m--;
                }else {
//
                    int add = 10-max-1;
                    for(int i=0; i<s.length(); i++){
                        s.replace(i, i+1, String.valueOf(s.charAt(i)-'0'+add));
                    }
                    for(int i=0; ; i++) {
                        //System.out.println(i);
                        if (i == s.length()) break;
                        if (s.charAt(i) == '9') {
                            s.delete(i, i + 1);
                            s.insert(i, '1');
                            s.insert(i + 1, '0');
                            i++;
                        } else {
                            s.replace(i, i + 1, String.valueOf(s.charAt(i) - '0' + 1));
                        }
                    }
                    m-=add+1;
                }
                //System.out.println(s);
            }
            System.out.println(s.length()%1000000009);
        }
    }

    // Fast Reader Class
    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;
        }
    }
}