This problem is different from World Fragments I and World Fragments II. Please read the statements carefully.
There are queries for you to answer.
For each query, you are given two non-negative decimal integers and
without leading zeros. You can apply the following operation to
any number of times (possibly zero):
Choose a digit in
.
Let either or
.
For example, when you can choose the digit
in
, then let
.
Find out the least number of operations needed to turn into
. Since the answer can be very large, output it modulo
. Print
if it is impossible to turn
into
.
The first line contains a positive integer
(
) — the number of queries.
Each query consists of a line that contains two integers
(
). Please note that in this version,
.
It is guaranteed that the sum of the lengths of the decimal representations of all
s does not exceed
.
For each query, print a decimal integer in a single line, denoting the answer modulo
. If it is impossible to turn
into
.
The operations in the third example are:.