#ABC4065. E - Popcount Sum 3

E - Popcount Sum 3

E - Popcount Sum 3

Time Limit: 2 sec / Memory Limit: 1024 MB

Problem Statement

You are given positive integers N and K. Find the sum, modulo 998244353, of all positive integers x that do not exceed N and satisfy the following condition:

the popcount of x is exactly K. You are given T test cases; solve each of them.

What is popcount?

For a positive integer y, popcount(y) denotes the number of 1 bits in the binary representation of y. For example, popcount(5)=2,popcount(16)=1,popcount(25)=3popcount(5)=2, popcount(16)=1, popcount(25)=3.

Constraints

1T1001≤T≤100 1N<2601≤N<2^{60}

1K601≤K≤60 T,N,T, N, and KK are integers.

Input

The input is given from Standard Input in the following format:

TT case1case 1 case2​case 2 ​⋮ caseTcase T casei​case i​ denotes the i-th test case. Each test case is given in the following format: NN KK

Output

Output T lines. The i-th line (1≤i≤T) should contain the answer for the i-th test case.

Sample Input 1

2
20 2
1234567890 17

Sample Output 1

100
382730918

Explantion

For the first test case, there are nine positive integers not exceeding 20 whose popcount is 22: 3,5,6,9,10,12,17,18,203,5,6,9,10,12,17,18,20. Their sum is 100. The remainder when 100 is divided by 998244353 is 100, so output 100 on the first line.Remember to output the sum modulo 998244353.