#P13712. 淘汰(Easy ver.)
淘汰(Easy ver.)
Description
Given two numbers and , you can perform the following two operations on any number of times:
Pay a cost of to assign .
Pay a cost of to assign .
Where and represent bitwise AND and bitwise OR operations respectively.
You need to determine the minimum cost to transform into . If it is impossible, output .
Help: What are bitwise AND and bitwise OR?
Input Format
This problem contains multiple test cases.
The first line of input contains an integer , representing the number of test cases.
For each test case, there is one line containing six integers , as described in the problem statement.
Output Format
For each test case, output one integer representing the answer.
5
1 15 2 14 3 5
1 3 3 14 9592 382
0 5 2 5 3492 12
194928 90283 59980 344444 182 959304
767894141 142877299 413934195 252884611 340885 421240
5
9974
12
-1
762125
Hint
Sample Explanation
-
For the first test case, you can spend a cost of to perform a bitwise OR with , obtaining , which meets the requirement. It can be proven that no better solution exists.
-
For the second test case, you can first spend to perform a bitwise OR with , obtaining , then spend to perform a bitwise AND with , obtaining , which meets the requirement. The total cost is .
-
For the fourth test case, it can be proven that no solution exists.
Data Constraints
Subtasks are used in this problem.
- Subtask 0 (0 pts): Sample cases.
- Subtask 1 (10 pts): .
- Subtask 2 (10 pts): , where is a non-negative integer.
- Subtask 3 (30 pts): .
- Subtask 4 (20 pts): .
- Subtask 5 (30 pts): .
For all test cases, it is guaranteed that , .
京公网安备 11011102002149号