#P1543C. Need for Pink Slips
Need for Pink Slips
Description
After defeating a Blacklist Rival, you get a chance to draw reward slip out of hidden valid slips. Initially, and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are , , and , respectively. There is also a volatility factor . You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was . Then,
- If the item was a Pink Slip, the quest is over, and you will not play any more races.
- Otherwise,
- If , the probability of the item drawn becomes and the item is no longer a valid item for all the further draws, reducing by . Moreover, the reduced probability is distributed equally among the other remaining valid items.
- If , the probability of the item drawn reduces by and the reduced probability is distributed equally among the other valid items.
For example,
- If and , after drawing Cash, the new probabilities will be .
- If and , after drawing Cash, the new probabilities will be .
- If and , after drawing Cash, the new probabilities will be .
- If and , after drawing Cash, the new probabilities will be .
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
The first line of input contains a single integer () — the number of test cases.
The first and the only line of each test case contains four real numbers , , and (, , ).
Additionally, it is guaranteed that each of , , and have at most decimal places.
For each test case, output a single line containing a single real number — the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed .
Formally, let your answer be , and the jury's answer be . Your answer is accepted if and only if .
Input
The first line of input contains a single integer () — the number of test cases.
The first and the only line of each test case contains four real numbers , , and (, , ).
Additionally, it is guaranteed that each of , , and have at most decimal places.
Output
For each test case, output a single line containing a single real number — the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed .
Formally, let your answer be , and the jury's answer be . Your answer is accepted if and only if .
Note
For the first test case, the possible drawing sequences are:
- P with a probability of ;
- CP with a probability of ;
- CMP with a probability of ;
- CMMP with a probability of ;
- MP with a probability of ;
- MCP with a probability of ;
- MCCP with a probability of .
For the second test case, the possible drawing sequences are:
- P with a probability of ;
- CP with a probability of ;
- CMP with a probability of ;
- MP with a probability of ;
- MCP with a probability of .
So, the expected number of races is equal to .