Parlay wagering lets a sports bettor try to win a large sum from a small initial wager. A parlay wager is a combination of individual, independent wagers that pays out only if no individual wager loses. The payout from each wager is applied ("parlayed") to the next wager in turn. If any individual wager loses, the bettor receives nothing. If any individual wager is a tie ("push"), that wager is ignored, which reduces the eventual payout.
The sports book quotes the payout rate of an individual wager as a money line: a non-zero integer from $-2000$ to $2000$. The money line is converted to a decimal multiplier as follows:
The multiplier is always truncated to three digits after the decimal point. The current wager is multiplied by this multiplier to determine the amount won, and the amount won is truncated to the cent (the sports book keeps the fractional cents). The amount won is then added to the wager, and that new total becomes the wager carried into the next individual wager.
The following worked example shows a five-way parlay wager:
| Money Line | Wager | Result | Multiplier | Amount Won |
|---|---|---|---|---|
| -170 | $10.00 | Win | 100/170 | $5.88 |
| -160 | $15.88 | Win | 100/160 | $9.92 |
| 125 | $25.80 | Win | 125/100 | $32.25 |
| -135 | $58.05 | Win | 100/135 | $42.95 |
| -140 | $101.00 | Win | 100/140 | $72.11 |
Subtotal won: $163.11. Original wager: $10.00. Total returned: $173.11.
The maximum payout for any parlay wager is $1,000,000. If the calculated total exceeds that amount, the total returned is $1,000,000.
For each parlay wager, print the total amount returned in dollars and cents on a single line, starting in the first column with no embedded or trailing whitespace. Print the leading dollar sign and insert commas at the thousands and millions positions as needed.
The first line of input contains a single positive integer: the number of parlay wagers.
Each parlay wager is given on several lines. The first line of a parlay wager contains two integers separated by a single space: the initial bet (an integer number of dollars) and the number of individual wagers. Each of the following lines describes one individual wager as its money line, a single space, and the result of the wager, which is one of Win, Tie, or Loss.
For each parlay wager, print one line containing the total amount returned in dollars and cents. Print the leading dollar sign and insert commas at the thousands and millions positions as needed.