Double it or Give it to the Next Person
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Alice and Bob are playing a strange game using coins.
Initially, Alice has x coins, and Bob has y coins. They take turns choosing one of the following options, starting with Alice:
  1. Try to double it. With probability p (p<\frac{1}{2}), his/her coin gets doubled up, and with the remaining probability, he/she loses all the coins and the game immediately.
  2. Pass to the next person. This literally means doing nothing in his/her turn. This operation costs d coins and is only possible when he/she has more than d coins
A player loses the game if he/she loses all his coins. Determine the probability that Alice wins if both players act optimally.

输入描述:

The first line contains an integer T (T\leq 10^4), denoting the number of test cases.

For each test case, the only line contains four integers x,y,d,c (1\leq x,y\leq 10^9, 1\leq d\leq 100, 1\leq c\leq 49) such that the parameter of the game is set as p=\frac{c}{100}.

输出描述:

For each test case, output an integer in a line, denoting the probability that Alice wins if both players act optimally. Under the input constraints of this problem, it can be shown that the answer can be written as \frac{P}{Q}, where P and Q are coprime integers and Q\not\equiv 0\pmod {998244353}. You need to output P\cdot Q^{-1}\bmod 998244353 as an answer, where Q^{-1} is the modular inverse of Q with respect to 998244353.
示例1

输入

复制
1
100 100 10 20

输出

复制
166374059