This problem is different from World Fragments I and World Fragments II. Please read the statements carefully.
There are
qqq queries for you to answer.
For each query, you are given two non-negative
decimal integers xxx and
yyy without leading zeros. You can apply the following operation to
xxx any number of times (possibly zero):
-
Choose a digit bbb in xxx.
-
Let either x←x+bx \gets x + bx←x+b or x←x−bx \gets x - bx←x−b.
For example, when
x=(616)10x = (616)_{10}x=(616)10 you can choose the digit
b=(1)10b=(1)_{10}b=(1)10 in
(61‾6)10(6\underline{1}6)_{10}(616)10, then let
x←x−b=(616)10−(1)10=(615)10x \gets x - b = (616)_{10} - (1)_{10} = (615)_{10}x←x−b=(616)10−(1)10=(615)10.
Find out the least number of operations needed to turn
xxx into
yyy. Since the answer can be very large, output it modulo
998244353998\,244\,353998244353. Print
−1-1−1 if it is impossible to turn
xxx into
yyy.