CF2245C MEXOR

Description

You are given a positive integer $ n $ and a non-negative integer $ k $ . Construct a permutation $ p $ of length $ n $ such that the following condition is satisfied: - Let $ f(i)=\operatorname{mex}([p_0,p_1,\ldots,p_i]) $ $ ^{\text{∗}} $ for every $ 0 \le i \lt n $ . Then, $ f(0) \oplus f(1) \oplus \ldots \oplus f(n-1) $ should equal $ k $ , where $ \oplus $ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that a permutation of length $ n $ is an array consisting of $ n $ distinct integers from $ 0 $ to $ n-1 $ in arbitrary order. For example, $ [1,2,0,4,3] $ is a permutation, but $ [0,1,1] $ is not a permutation ( $ 1 $ appears twice in the array), and $ [0,2,3] $ is also not a permutation ( $ n=3 $ but there is $ 3 $ in the array). $ ^{\text{∗}} $ The minimum excluded (MEX) of a collection of integers $ c_1, c_2, \ldots, c_k $ is defined as the smallest non-negative integer $ x $ which does not occur in the collection $ c $ .

Input Format

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^4 $ ). The description of the test cases follows. The only line of each test case contains two integers $ n $ and $ k $ ( $ 1 \le n \le 2 \cdot 10^5 $ , $ 0 \le k \le 10^9 $ ). It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .

Output Format

For each test case, if no such permutation exists, output "NO". Otherwise, first output "YES" on a single line. Then, output $ n $ distinct integers $ p_0,p_1,\ldots,p_{n-1} $ ( $ 0 \le p_i \lt n $ ), representing the permutation $ p $ you constructed. If there are multiple permutations satisfying the requirement, you may output any of them. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Explanation/Hint

In the first and second test cases, the only permutation of length $ 1 $ is $ [0] $ , with $ f(0)=\operatorname{mex}([0])=1 $ . In the fourth test case, it can be proven that no permutation of length $ 4 $ exists such that $ f(0) \oplus f(1) \oplus f(2) \oplus f(3)=8 $ . In the fifth test case, the values of $ f(i) $ for $ 0 \le i \lt n $ are as follows: - $ f(0)=\operatorname{mex}([3])=0 $ , - $ f(1)=\operatorname{mex}([3,0])=1 $ , - $ f(2)=\operatorname{mex}([3,0,2])=1 $ , - $ f(3)=\operatorname{mex}([3,0,2,1])=4 $ , - $ f(4)=\operatorname{mex}([3,0,2,1,4])=5 $ , Since $ f(0) \oplus f(1) \oplus f(2) \oplus f(3) \oplus f(4)=0\oplus 1 \oplus 1 \oplus 4 \oplus 5=1 $ , $ p=[3,0,2,1,4] $ is a valid permutation.