import java.util.*;

public class SuperDPTopDown {
	long[][] memo = new long[10][13];

	long rec(int first, int length){
		if (length==0) return 1;
		if (memo[first][length]!=-1)
			return memo[first][length];

		long ret = 0;
		for (int i=0; i<10; i++)
			if (i!=4 && !(first==1 && i==3))
				ret += rec(i,length-1);
		return memo[first][length] = ret;
	}

	long countFloors(char[] k){
		long floors = 0;
		for (int i=0; i<k.length; i++)
			for (int j=0; j<k[i]-'0'; j++)
				if (j!=4 && !((i>0?k[i-1]-'0':0)==1 && j==3))
					floors += rec(j,k.length-i-1);
		return floors;
	}

	void solve(){
		for (long[] m : memo) Arrays.fill(m,-1);
		Scanner scan = new Scanner(System.in);
		int T = scan.nextInt();
		while (T-- > 0){
			long floors = countFloors(scan.next().toCharArray());
			System.out.println(floors * scan.nextInt());
		}
		scan.close();
	}

	public static void main(String[] args){
		new SuperDPTopDown().solve();
	}
}
