You are given an integer and a digit . You have to count the number of pairs and such that
and do not contain any leading zeros
Last digit of is equal to the first digit of
First digit of is equal to last digit of and
Except for the the first and last digits of both integer and , there must be at least one digit present in both and which is equal to the given digit .
Print the answer modulo .
First line contains an integer denoting test cases. Then line follows two space separated integers and .
Print a single line the the number of pair satisfy the condition for each test cases.
Input | Output |
---|---|
5 111 1 222 2 245 3 555 3 100 5 | 1 4 4 25 0 |