Kingdom Rush
Time limit5sMemory limit512 MB
Earn one-star and two-star clears with star thresholds in an order that finishes every level with two stars in the fewest plays.
Problem
Ryan is playing Kingdom Rush, a single-player tower defense game made by Ironhide Game Studio. In this game you earn stars by clearing levels, and more stars make the player stronger. So even if Ryan cannot clear level 2 right now, he may be able to clear it after collecting stars on level 1.
The rules in this problem are not the rules of the real game. You do not need to have played it to solve the problem.
Here, clearing a level gives either a one-star rating or a two-star rating. Stars are earned as follows.
- Clearing a level you have never cleared before with a one-star rating earns 1 star.
- Clearing a level you have never cleared before with a two-star rating earns 2 stars.
- Clearing a level you had cleared before only with a one-star rating, this time with a two-star rating, earns 1 more star.
In any other case you earn no stars.
Ryan cannot clear every level right away. To clear level with a one-star rating he needs stars, and to clear it with a two-star rating he needs stars. is not smaller than .
For example, consider a game with two levels. Level 1 needs 0 stars for a one-star rating and 1 star for a two-star rating. Level 2 needs 0 stars for a one-star rating and 2 stars for a two-star rating. Ryan can play like this.
- He starts with 0 stars, so he can clear level 1 or level 2 with a one-star rating. He clears level 1 with a one-star rating and then has 1 star.
- Now he can clear level 2 with a one-star rating, or level 1 with a two-star rating. He clears level 1 with a two-star rating and then has 2 stars.
- Now he can clear level 2 with a two-star rating. He does that and then has 4 stars.
- Every level has a two-star rating, and he has 2 stars per level for 4 in total. He cleared a level 3 times: level 1 twice and level 2 once.
Find the minimum number of times Ryan has to clear a level so that every level has a two-star rating.
Input
The first line contains the number of test cases . Each test case starts with a line containing the number of levels . The next lines describe the levels. The th of them contains the integers and , the number of stars needed for a one-star rating and for a two-star rating on level .
Limits
Output
For each test case, print one line of the form Case #x: y, where is the test case number starting from 1 and is the minimum number of times Ryan has to clear a level until every level has a two-star rating. If a two-star rating on every level is impossible, print Too Bad in place of , with exactly that capitalization.