File size: 2,894 Bytes
ab396f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
Melody is visiting the beautiful city of Stockholm, Sweden! Stockholm has a
number of waterways flowing through it, dividing the city up into a number of
islands. Like most visitors, Melody was surprised to learn that there are in
fact an infinite number of waterways and an infinite number of islands!
The waterways flow between an infinite number of junctions, which are numbered
with non-negative integers starting from 0. There's an infinitely-long
waterway flowing into junction 0, and then for each junction _j_, there are
two waterways flowing out of it into junctions 2_j_+1 and 2_j_+2. This results
in each junction having exactly three incident waterways.
An island is a connected region of land. Each waterway is adjacent to two
different islands (one on each side of it), and has a bridge connecting those
two islands together. Each junction is adjacent to three different islands
(the distinct islands adjacent to its incident waterways).
A portion of Stockholm (including junctions 0 to 14) is illustrated below,
with islands represented as contiguous regions filled with various shades of
grey, and bridges between them represented as brown curves:
![]({{PHOTO_ID:923060468192530}})
Melody is currently aboard a friend's boat parked at some junction **A**, but
she wants to visit another friend's boat which is parked at a different
junction **B**. She'll begin by getting out of the first boat onto any of the
three islands of her choice which are adjacent to junction **A**. She'll then
walk on land until she arrives at any of the three islands which are adjacent
to junction **B**, potentially crossing some bridges between islands along the
way. Finally, she'll board the second boat from that island.
Melody's not a big fan of walking on Stockholm's rather unevenly cobbled
bridges, so she'd like to cross as few of them as possible along the way. Help
her determine the minimum number of bridges which she must cross to walk from
junction **A** to junction **B**!
For example, the following illustration indicates the only optimal path from
junction 8 to junction 5 in red (crossing only 1 bridge), and one of the
optimal paths from junction 12 to junction 3 in yellow (crossing only 2
bridges):
![]({{PHOTO_ID:293195401822038}})
### Input
Input begins with an integer **T**, the number of times Melody needs to travel
between two junctions. For each trip, there is a single line containing the
space-separated integers **A** and **B**.
### Output
For the _i_th trip, output a line containing "Case #_i_: " followed by the
minimum number of bridges which Melody must cross to walk from junction **A**
to junction **B**.
### Constraints
1 ≤ **T** ≤ 2,000
0 ≤ **A**, **B** ≤ 1018
**A** ≠ **B**
### Explanation of Sample
The first two cases are described above.
In the third and fourth cases, it's unnecessary for Melody to cross any
bridges.
|