import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		StringBuilder reStringBuilder=new StringBuilder();
		int N=cin.nextInt();
		for(int i=0;i<N;i++) {
			int n=cin.nextInt();
			int m=cin.nextInt();
			String num=String.valueOf(n);
			for(int j=0;j<num.length();j++) {
				int d=Integer.parseInt(num.charAt(j)+"")+m;
				reStringBuilder.append(d);
			}
			System.out.println((int)reStringBuilder.toString().length()%Math.pow(10,9));
			reStringBuilder=new StringBuilder();
		}
		cin.close();
	}
}

   		    	 	 	  	 				 	    			