#P1815D. XOR Counting
XOR Counting
No submission language available for this problem.
Description
Given two positive integers and . Find the sum of all possible values of , where are non-negative integers such that .
Note that all possible values should be counted in the sum exactly once.
As the answer may be too large, output your answer modulo .
Here, denotes the bitwise XOR operation.
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first and only line of each test case contains two integers and () — the sum and the number of integers in the set, respectively.
For each test case, output the sum of all possible values of among all non-negative integers with . As the answer may be too large, output your answer modulo .
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first and only line of each test case contains two integers and () — the sum and the number of integers in the set, respectively.
Output
For each test case, output the sum of all possible values of among all non-negative integers with . As the answer may be too large, output your answer modulo .
Note
For the first test case, we must have , so it's the only possible value of , therefore our answer is .
For the second test case, can be or , in which are respectively. So can be or , therefore our answer is .
For the third test case, must be all , so . Therefore our answer is .