Taha has got a standard deck of cards with him. In addition to the 52 regular ones, there are 2 joker cards. Every regular card has a rank and a suit. The ranks in ascending order are: A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q and K. The suit of a card can be clubs, diamonds, hearts or spades. That means there are 13 clubs, 13 diamonds, 13 hearts and 13 spades - which adds up to 52. The joker cards have no ranks or suits.
One day, Sara gave Taha a challenge. First she randomly shuffles the 54 cards and starts placing one card after another, face-up, on a table. What is the expected number of cards Sara has to place so that there are at least C clubs, D diamonds, H hearts and S spades on the table? Whenever a joker card is encountered, Taha has to assign it to some suit so that the expected number of cards to reach the goal is minimized. The decision of assigning the joker card to some suit has to be made instantly (i.e. before Sara puts the next card on the table). Note that the assignments of the two joker cards don't necessarily need to be the same.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case starts with a line containing four integers in the order C, D, H and S. Each of these integers will be in the range [0, 15].
Output
For each case, print the case number first. Then output the expected number of cards Sara needs to place on the table to achieve the goal. If it's impossible to reach the goal, irrespective of what assignments Sara opts for, output '-1' (without the quotes) instead. Errors less than 10-6 will be ignored.
Sample
Sample Input | Sample Output |
---|---|
4 0 0 0 0 15 13 13 13 1 2 3 4 15 15 15 15 | Case 1: 0.0000000000 Case 2: 54.0000000000 Case 3: 16.3928186102 Case 4: -1 |
Notes
- For case 1, there is no need to place any card as all required values are 0.
- For case 2, we must place all the 54 cards to reach the goal.
- For case 3, note that output isn't always an integer.
- For case 4, 60 Cards? No way!!