You are given an integer N and a digit D. You have to count the number of pairs A and B(1≤A,B≤N) such that
A and B do not contain any leading zeros
Last digit of A is equal to the first digit of B
First digit of A is equal to last digit of B and
Except for the the first and last digits of both integer A and B, there must be at least one digit present in both A and B which is equal to the given digit D.
Print the answer modulo 1000000007(109+7).
Input
First line contains an integer T(T≤100000) denoting test cases. Then T line follows two space separated integers N and D.
1<=N<=1018
0<=D<=9
Output
Print a single line the the number of pair satisfy the condition for each test cases.