This problem is different from World Fragments I and World Fragments III. Please read the statements carefully.
There are queries for you to answer. Only when you have answered the previous queries can you get the next query.
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
. 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
. Let the answer of the previous query be
. Specifically,
is considered to be
for the first query. The decimal integers
in the given query are shown as below, where
denotes the bitwise exclusive OR operation.
It is guaranteed that
holds for each query.
For each query, print a decimal integer in a single line, denoting the answer. If it is impossible to turn
into
.
The actual queries and the operations in their optimal ways are shown as followings:
, optimal
operations:
.
, optimal
operations:
.
, optimal
operations:
.
, impossible.
, optimal
operations:
.
, impossible.