import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Solution {

    /*
     * Complete the 'countingValleys' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts following parameters:
     *  1. INTEGER steps
     *  2. STRING path
     */

    public static void main(String args[]) {
    // Write your code here
    final int mod=1000000007;
    Scanner scan =new Scanner(System.in);
    int t=scan.nextInt();
    while(t>0)
    {
    int n=scan.nextInt();
    int m=scan.nextInt();
    String str=String.valueOf(n);
    System.out.println(str);
    int len=str.length();
    String ans="";
    int i=0;
    while(m-->0){
    
    while(i<=len-1)
    {
        
        int x=Integer.parseInt(Character.toString(str.charAt(i)))+1;
        //System.out.println("x = "+x);
        ans=ans+x;
        //System.out.println("ans = "+ans);
        i++;
    }
    int ans1=Integer.parseInt(ans)%mod;
    ans=String.valueOf(ans1);
    }
    System.out.println(ans.length());
    t--;
    } 
    }
}

