Codeforces Round 768 (Div. 2)
C
And Matching
Codeforces
未评级
原题
← BD →
翻译中…

You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.

翻译中…

Find $\frac{n}{2}$ 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 $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
翻译中…

If there are many solutions, print any of them, if there is no solution, print $-1$ instead.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows.

翻译中…

Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).

翻译中…

The sum of $n$ over all test cases does not exceed $2^{16}$. 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 $-1$.

翻译中…

Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.

翻译中…

If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.

翻译中…

Note

翻译中…

In the first test, $(0\&3)+(1\&2) = 0$.

翻译中…

In the second test, $(0\&2)+(1\&3) = 1$.

翻译中…

In the third test, $(0\&1)+(2\&3) = 2$.

翻译中…

In the fourth test, there is no solution.

翻译中…

样例

Input #1
4
4 0
4 1
4 2
4 3
Output #1
0 3
1 2
0 2
1 3
0 1
2 3
-1
InputCopy OutputCopy
题目信息
题号
1631C
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。