Simulate B bottles poured into the top glass of a wine pyramid where overflow splits into three glasses below and report the amount in glass N on level L.
Medium6SimulationDynamic programmingNo attempts yetTime limit5sMemory limit512 MBAt a New Year's Eve party the wine glasses are stacked into a pyramid. The top level holds one glass, the second level holds three, the third holds six, and the fourth holds ten.

Each glass is identified by two numbers, L and N. L is the level the glass sits on and N is its number within that level. The glasses on one level form a triangle. They are numbered from the top row downwards, and from left to right within each row.
Level 1:
1
Level 2:
1
2 3
Level 3:
1
2 3
4 5 6
Level 4:
1
2 3
4 5 6
7 8 9 10
Write a glass on level L as row r, position c inside that row, where 1≤c≤r≤L. Its number is then N=r(r−1)/2+c.
Each glass holds 250ml of wine. The bartender opens bottles of 750ml each and pours into the top glass (L=1, N=1).
Once a glass is full, the wine that overflows splits equally among the three glasses on the level below that touch it, and none of it spills outside. Wine never flows into a neighbour on the same level, and it never skips a level. When the glass (r,c) on level L overflows, the wine runs into the glasses (r,c), (r+1,c) and (r+1,c+1) on level L+1. For example, when the glass with L=2 and N=2 overflows, the wine runs into glasses 2, 4 and 5 on level 3.
After the bartender has poured all B bottles, report how much wine in ml sits in glass number N on level L.
The first line contains the number of test cases T. Each of the next T lines holds one test case with three integers B, L and N separated by spaces. B is the number of bottles the bartender pours, L is the level of the glass, and N is the number of the glass on that level.
For each test case print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the amount of wine in ml in that glass. Round y to seven decimal places and print all seven digits.