Bathroom Stalls

Simulate K people choosing the emptiest interval by a tie-break rule, and report the gap sizes of the K-th chosen stall.

Medium7HeapGreedyMathSimulationInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

A bathroom has N+2N + 2 stalls in a single row. The stalls at the left and right ends are permanently occupied by the bathroom guards, and the other NN stalls are for users.

Whenever someone enters the bathroom, they pick a stall as far from other people as possible. The rule they follow is deterministic. For each empty stall SS they compute two values, LSL_S and RSR_S. LSL_S is the number of empty stalls between SS and the closest occupied stall to its left, and RSR_S is the same count to the right. They first keep only the stalls where min(LS,RS)\min(L_S, R_S) is maximal. If exactly one stall remains, they take it. Otherwise they take the one among those where max(LS,RS)\max(L_S, R_S) is maximal, and if several are still tied, the leftmost one.

KK people enter one after another. Each person picks a stall before the next one arrives, and nobody ever leaves.

For the stall SS picked by the last of the KK people, report max(LS,RS)\max(L_S, R_S) and min(LS,RS)\min(L_S, R_S).

Input

The first line contains the number of test cases TT. Each of the next TT lines describes one test case with two integers NN and KK.

Limits

  • 1T1001 \le T \le 100
  • 1KN1 \le K \le N
  • 1N1061 \le N \le 10^6

Output

For each test case, print one line in the form Case #x: y z, where xx is the test case number starting from 1, yy is max(LS,RS)\max(L_S, R_S) and zz is min(LS,RS)\min(L_S, R_S) for the stall SS chosen by the last person to enter.

Note

In the first test case, the first person takes the left one of the two middle stalls, which gives O.O..O. Here O is an occupied stall and . is an empty one. The second and last person then takes the stall immediately to the right, leaving 1 empty stall on one side and none on the other.

In the second test case, the first person takes the middle stall, which gives O..O..O. The second and last person then takes the leftmost stall.

In the third test case, the first person takes the left one of the two middle stalls, which gives O..O...O. The second person takes the middle of the three consecutive empty stalls.

In the fourth test case, every stall ends up occupied no matter which stalls are chosen.

In the fifth test case, the only person takes the left one of the two middle stalls.