| <p> | |
| 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! | |
| </p> | |
| <p> | |
| 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 <em>j</em>, | |
| there are two waterways flowing out of it into junctions 2<em>j</em>+1 and 2<em>j</em>+2. This results in each junction having exactly three incident waterways. | |
| </p> | |
| <p> | |
| 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). | |
| </p> | |
| <p> | |
| 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: | |
| </p> | |
| <img width="500px" src="{{PHOTO_ID:923060468192530}}" /> | |
| <p> | |
| Melody is currently aboard a friend's boat parked at some junction <strong>A</strong>, but she wants to visit another friend's boat which is parked at a different junction <strong>B</strong>. | |
| She'll begin by getting out of the first boat onto any of the three islands of her choice which are adjacent to junction <strong>A</strong>. | |
| She'll then walk on land until she arrives at any of the three islands which are adjacent to junction <strong>B</strong>, | |
| potentially crossing some bridges between islands along the way. Finally, she'll board the second boat from that island. | |
| </p> | |
| <p> | |
| 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 <strong>A</strong> to junction <strong>B</strong>! | |
| </p> | |
| <p> | |
| 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): | |
| </p> | |
| <img width="500px" src="{{PHOTO_ID:293195401822038}}" /> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of times Melody needs to travel between two junctions. | |
| For each trip, there is a single line containing the space-separated integers <strong>A</strong> and <strong>B</strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <em>i</em>th trip, output a line containing "Case #<em>i</em>: " followed by the minimum number of bridges which Melody must cross to walk from junction | |
| <strong>A</strong> to junction <strong>B</strong>. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 2,000 <br /> | |
| 0 ≤ <strong>A</strong>, <strong>B</strong> ≤ 10<sup>18</sup> <br /> | |
| <strong>A</strong> ≠ <strong>B</strong> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| The first two cases are described above. | |
| </p> | |
| <p> | |
| In the third and fourth cases, it's unnecessary for Melody to cross any bridges. | |
| </p> | |