#P1630A. And Matching
And Matching
No submission language available for this problem.
Description
You are given a set of ( is always a power of ) elements containing all integers exactly once.
Find pairs of elements such that:
- Each element in the set is in exactly one pair.
- The sum over all pairs of the bitwise AND of its elements must be exactly equal to . Formally, if and are the elements of the -th pair, then the following must hold: where denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print instead.
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers and (, is a power of , ).
The sum of over all test cases does not exceed . All test cases in each individual input will be pairwise different.
For each test case, if there is no solution, print a single line with the integer .
Otherwise, print lines, the -th of them must contain and , the elements in the -th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
Input
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers and (, is a power of , ).
The sum of over all test cases does not exceed . All test cases in each individual input will be pairwise different.
Output
For each test case, if there is no solution, print a single line with the integer .
Otherwise, print lines, the -th of them must contain and , the elements in the -th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
Samples
Note
In the first test, .
In the second test, .
In the third test, .
In the fourth test, there is no solution.