Limits 4s, 512 MB

The numbers 1,2,3,n1,2,3, \cdots n (each integer from 11 to nn once) are written on a board. In one operation, Jesse can choose any number xx from the board and replace it by x2\lfloor \frac{x}{2} \rfloor(Half of xx rounded down). Jesse wants to minimize the sum of the integers after performing exactly kk operations. Help Jesse.

Input

The first line contains T(1T105)T (1 \leq T \leq 10^5), the number of testcases.

Each of the following TT lines contain two space separated integers, nn and kk(1n,k109)(1 \leq n, k \leq 10^9).

Output

For each testcase, print a single line containing a single integer, the minimum sum after performing exactly kk operations.

Sample

InputOutput
3
4 1
4 3
3 10
8
5
0

For the first case, 1,2,3,41, 2, 3, 4 are written. Jesse picks x=3x = 3 and replaces it by 32=1\lfloor \frac{3}{2} \rfloor = 1. Now the board contains 1,2,1,41, 2, 1, 4 with sum 88.

For the second case, initially the board contains 1,2,3,41, 2, 3, 4.

  • For the first operation, Jesse chooses x=1x = 1, replaces it by 00. The board contains 0,2,3,40, 2, 3, 4.

  • For the second operation, Jesse chooses x=4x = 4, replaces it by 22. The board contains 0,2,3,20, 2, 3, 2.

  • For the third operation, Jesse chooses x=3x = 3, replaces it by 11. The board contains 0,2,1,20, 2, 1, 2.

For the third case, Jesse can make everything 00.


Submit

Login to submit.

Statistics

0% Solution Ratio
Toph uses cookies. By continuing you agree to our Cookie Policy.