Official algorithmic problem description and constraints.
You are given two integers π
and π
. You are allowed to perform the following operation any number of times (including zero):
After performing a sequence of operations, you want the value of π
to become exactly π
.
Find a sequence of at most 100
operations (values of π₯
used in each operation) that transforms π
into π
, or report that it is impossible.
Note that you are not required to find the minimum number of operations, but any valid sequence of at most 100
operations.
Input
The first line of input contains a single integer π‘
(1β€π‘β€1000
) β the number of test cases.
Each test case contains two integers π
and π
(1β€π,πβ€10
9
).
Output
For each test case, if it is impossible to obtain π
from π
using the allowed operations, print a single line containing β1
.
Otherwise, on the first line print a single integer π
(0β€πβ€100
) β the number of operations. On the second line print π
integers (π₯
1
,π₯
2
,β¦,π₯
π
) β the chosen values of π₯
in the order you apply them.
If there are multiple valid sequences, you may print any one of them.
Example
Input
Copy
6 9 6 13 13 292 929 405 400 998 244 244 353
Output
Copy
2 7 8 0 -1 1 5 2 25 779 -1
Note
For the first test case,
Thus, we can make π=π
.
For the fourth test case, choosing π₯=5
makes π=π
.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.