King of the Casino
Xem dạng PDFIn the final showdown at the Las Vegas Casino, two fierce rivals, Kael and Roc, are the last players standing. Currently, Kael has ~x~ chips and Roc has ~y~ chips.
The two will compete in a series of rounds until one player runs out of chips and is eliminated. Let ~z = \min(x, y)~. The outcome of each round follows these rules:
Kael wins: He takes ~z~ chips from Roc. Kael now has ~x + z~ chips, while Roc has ~y - z~ chips.
Roc wins: He takes ~z~ chips from Kael. Kael now has ~x - z~ chips, while Roc has ~y + z~ chips.
Both player draw: No chips are exchanged, and the stack sizes remain ~x~ and ~y~.
Zara, a professional analyst observing the match, has calculated the probabilities for a single round, that Kael has a winning probability of ~p_k~, while Roc has a winning probability of ~p_r~, and the probability of a tie between them is ~1 - p_k - p_r~.
With this data, given that the match will end with one of them running out of chips, Zara wants to know the overall probability that Kael will be the ultimate winner of the competition.
Input
The first line contains a positive integer ~T~ (~1 \leq T \leq 10^5~) — the number of datasets. Each dataset is described as follows:
The first line contains three non-negative integers ~p_k~, ~p_r~, ~b~ (~0 \leq p_k + p_r \leq b \leq 10^8~) — the winning probability of Kael is ~\frac{p_k}{b}~, and the winning probability of Roc is ~\frac{p_r}{b}~.
The second line contains two positive integers ~x~, ~y~ (~1 \leq x, y \leq 10^6~) — the number of chips of Kael and Roc respectively.
The data guarantees that ~\sum{x_i}~ and ~\sum{y_i}~ do not exceed ~10^6~.
Output
The probability that Kael wins overall, expressed in the form ~P \times Q^{-1}~ ~mod~ ~998244353~, where ~Q^{-1}~ is the modular inverse of the denominator modulo ~998244353~.
Sample Input 1
2
2 2 5
4 4
1 2 4
7 5
Sample Output 1
499122177
744721978
Notes
In the first test case, since both players have the same number of chips and the same winning probabilities, their winning probability is ~\frac{1}{2}~.
Bình luận