| <p> | |
| This weekend, the long-awaited BIT (Boomerang Invitational Tournament) will be taking place! | |
| <strong>N</strong> of the finest boomerangists will be competing in a randomly-seeded single-elimination bracket. | |
| </p> | |
| <p> | |
| For those unfamiliar with this tournament format, the process can be modelled as follows: | |
| </p> | |
| <p> | |
| <ol> | |
| <li> The <strong>N</strong> competitors are arranged in a queue (an ordered list), in some order </li> | |
| <li> If the queue currently contains only 1 competitor, the tournament ends with them as the champion </li> | |
| <li> Otherwise, the first 2 competitors in the front of the queue are removed, and they play a match against one another </li> | |
| <li> The winner of that match is re-inserted into the queue, at the back </li> | |
| <li> Repeat from step 2 </li> | |
| </ol> | |
| </p> | |
| <p> | |
| The one-on-one matches in this tournament are, of course, boomerang duels to the death. | |
| If the <strong>i</strong>th and <strong>j</strong>th competitors face off against one another, the <strong>i</strong>th competitor will win if | |
| <strong>W<sub>i,j</sub></strong> = 1. Otherwise, if <strong>W<sub>i,j</sub></strong> = 0, the <strong>j</strong>th competitor will win. | |
| Note that, for all (1 ≤ <strong>i</strong>, <strong>j</strong> ≤ <strong>N</strong>), | |
| <strong>W<sub>i,j</sub></strong> = 0 or 1, and <strong>W<sub>i,i</sub></strong> = 0 (no one will play against themselves anyway), | |
| and <strong>W<sub>i,j</sub></strong> ≠ <strong>W<sub>j,i</sub></strong> (if <strong>i</strong> ≠ <strong>j</strong>). | |
| Those are the only constraints. It's possible that, for example, competitor A can beat B, B can beat C, and C can beat A. | |
| </p> | |
| <p> | |
| Once the tournament is over, each boomerangist is given a placing (even if they didn't survive the competition). A given competitor <strong>c</strong>'s placing is an | |
| integer one greater than the number of competitors who won strictly more matches than <strong>c</strong> did. | |
| </p> | |
| <p> | |
| For each boomerangist, you'd like to know both the best (smallest) and the worst (largest) placing they could possibly end up with, | |
| given that the initial ordering of the competitors (in step 1 of the tournament) is unknown. | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of tournaments. | |
| For each tournament, there is first a line containing the integer <strong>N</strong>. | |
| Then follow <strong>N</strong> lines, the <strong>i</strong>th of which contains the space-separated integers | |
| <strong>W<sub>i,1</sub></strong> through <strong>W<sub>i,N</sub></strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <strong>i</strong>th tournament, print a line containing "Case #<strong>i</strong>: " followed by | |
| <strong>N</strong> lines that each contain two space-separated integers. The first integer on the <strong>i</strong>th line | |
| should be the best possible placing for the <strong>i</strong>th competitor, and the second should be the worst possible placing. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 250 <br /> | |
| <strong>N</strong> = 2<sup><strong>K</strong></sup> where <strong>K</strong> is an integer and 0 ≤ <strong>K</strong> ≤ 4 <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the second tournament, the first competitor will always beat the second competitor, so the first competitor will finish in 1st place, and the other in 2nd place. | |
| In the third tournament, the first competitor never loses, so they will finish in 1st place. The fourth competitor never wins, so they will finish tied for 3rd place with | |
| the other competitor who loses their initial match. | |
| The other two competitors will either lose their first match (if initially paired with the first competitor) or their second match (if initially paired with the fourth competitor), | |
| so they can each finish in 2nd place, or tied for 3rd place. | |
| </p> | |