#P1815D. XOR Counting

    ID: 8395 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>bitmaskscombinatoricsdpmath*2600

XOR Counting

No submission language available for this problem.

Description

Given two positive integers nn and mm. Find the sum of all possible values of a1a2ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m, where a1,a2,,ama_1,a_2,\ldots,a_m are non-negative integers such that a1+a2++am=na_1+a_2+\ldots+a_m=n.

Note that all possible values a1a2ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m should be counted in the sum exactly once.

As the answer may be too large, output your answer modulo 998244353998244353.

Here, \bigoplus denotes the bitwise XOR operation.

Each test consists of multiple test cases. The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first and only line of each test case contains two integers nn and mm (0n1018,1m1050\le n\le 10^{18}, 1\le m\le 10^5) — the sum and the number of integers in the set, respectively.

For each test case, output the sum of all possible values of a1a2ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m among all non-negative integers a1,a2,,ama_1,a_2,\ldots,a_m with a1+a2++am=na_1+a_2+\ldots+a_m=n. As the answer may be too large, output your answer modulo 998244353998244353.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first and only line of each test case contains two integers nn and mm (0n1018,1m1050\le n\le 10^{18}, 1\le m\le 10^5) — the sum and the number of integers in the set, respectively.

Output

For each test case, output the sum of all possible values of a1a2ama_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m among all non-negative integers a1,a2,,ama_1,a_2,\ldots,a_m with a1+a2++am=na_1+a_2+\ldots+a_m=n. As the answer may be too large, output your answer modulo 998244353998244353.

Sample Input 1

7
69 1
5 2
0 10
420 69
12 26
73 34
1000000000000000000 10

Sample Output 1

69
6
0
44310
42
1369
216734648

Note

For the first test case, we must have a1=69a_1=69, so it's the only possible value of a1a_1, therefore our answer is 6969.

For the second test case, (a1,a2)(a_1,a_2) can be (0,5),(1,4),(2,3),(3,2),(4,1)(0,5), (1,4), (2,3), (3,2), (4,1) or (5,0)(5,0), in which a1a2a_1\bigoplus a_2 are 5,5,1,1,5,55,5,1,1,5,5 respectively. So a1a2a_1\bigoplus a_2 can be 11 or 55, therefore our answer is 1+5=61+5=6.

For the third test case, a1,a2,,a10a_1,a_2,\ldots,a_{10} must be all 00, so a1a2a10=0a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_{10}=0. Therefore our answer is 00.