Many Prizes (Small)

For a Swiss-style tournament of 2^N ranked teams with P prizes, report the worst-ranked team guaranteed a prize and the worst-ranked team that can earn one.

Medium7CombinatoricsGreedyNo attempts yetTime limit5sMemory limit512 MB

Problem

A tournament runs with 2N2^N teams, and PP identical prizes go to the teams that finish in places 00 through P1P-1.

The teams are numbered 00 through 2N12^N-1. When team ii plays team jj, team ii wins if and only if i<ji < j. The lower-numbered team always wins.

The tournament list is an ordering of all 2N2^N teams in the tournament. That order decides which teams meet, and in which round.

How the tournament runs

The tournament has NN rounds. Each team keeps a record, the results of the games it has played so far. A team that won its first game, lost its second and won its third has the record [W, L, W]. A team that has played no games has an empty record.

In each round, every team plays one game against a team with the same record. Among the teams with a given record, the first in the tournament list plays the second, the third plays the fourth, and the rest pair up the same way.

After NN rounds every team has a different record. Teams are ranked in reverse lexicographic order of their records, so [W, W, W] > [W, W, L] > [W, L, W] > ... > [L, L, L].

Here is how a tournament with N=3N = 3 and the tournament list 2, 4, 5, 3, 6, 7, 1, 0 plays out.

Round 1   2 vs 4 (2 wins)   5 vs 3 (3 wins)   6 vs 7 (6 wins)   1 vs 0 (0 wins)

Round 2   record [W]: 2 vs 3 (2 wins)   6 vs 0 (0 wins)
          record [L]: 4 vs 5 (4 wins)   7 vs 1 (1 wins)

Round 3   record [W,W]: 2 vs 0 (0 wins)
          record [W,L]: 3 vs 6 (3 wins)
          record [L,W]: 4 vs 1 (1 wins)
          record [L,L]: 5 vs 7 (5 wins)

Final     place 0: team 0 [W,W,W]    place 4: team 1 [L,W,W]
          place 1: team 2 [W,W,L]    place 5: team 4 [L,W,L]
          place 2: team 3 [W,L,W]    place 6: team 5 [L,L,W]
          place 3: team 6 [W,L,L]    place 7: team 7 [L,L,L]

With N=3N = 3 and P=4P = 4, this list gives the prizes to teams 0, 2, 3 and 6. The list shows an ordering in which team 1 misses a prize, and team 0 takes a prize under every ordering, so the largest-numbered team that always takes a prize is team 0. The same list shows that team 6 can take a prize, and team 7 takes one under no ordering, so the largest-numbered team that could take a prize is team 6.

Given NN and PP, find the largest-numbered team that takes a prize whatever the tournament list is, and the largest-numbered team that takes a prize for at least one tournament list.

Input

The first line has the number of test cases TT. Each of the next TT lines has two integers NN and PP separated by a space. The tournament has 2N2^N teams and PP prizes.

  • 1T1001 \le T \le 100
  • 1N101 \le N \le 10
  • 1P2N1 \le P \le 2^N

Output

For each test case print one line in the form "Case #x: y z", where xx is the test case number starting from 11, yy is the largest-numbered team that takes a prize whatever the tournament list is, and zz is the largest-numbered team that takes a prize for some tournament list.