eolymp
bolt
Try our new interface for solving problems
Problems

Bathroom Stalls

Bathroom Stalls

A certain bathroom has n + 2 stalls in a single row; the stalls on the left and right ends are permanently occupied by the bathroom guards. The other n stalls are for users.

Whenever someone enters the bathroom, they try to choose a stall that is as far from other people as possible. To avoid confusion, they follow deterministic rules: For each empty stall s, they compute two values ls and rs, each of which is the number of empty stalls between s and the closest occupied stall to the left or right, respectively. Then they consider the set of stalls with the farthest closest neighbor, that is, those s for which min(ls, rs) is maximal. If there is only one such stall, they choose it; otherwise, they choose the one among those where max(ls, rs) is maximal. If there are still multiple tied stalls, they choose the leftmost stall among those.

k people are about to enter the bathroom; each one will choose their stall before the next arrives. Nobody will ever leave.

When the last person chooses their stall s, what will the values of max(ls, rs) and min(ls, rs) be?

Input

The first line gives the number of test cases t (1t100). t lines follow. Each line describes a test case with two integers n (1n1018) and k (1kn) as described above.

Output

For each test case, output one line containing Case #x: y z, where x is the test case number (starting from 1), y is max(ls, rs), and z is min(ls, rs) as calculated by the last person to enter the bathroom for their chosen stall s.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5
4 2
5 2
6 2
1000 1000
1000 1
Output example #1
Case #1: 1 0
Case #2: 1 0
Case #3: 1 1
Case #4: 0 0
Case #5: 500 499
Source 2017 Google Code Jam Qualification Round, Problem C