409222: GYM103463 B Hsueh- play balls

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Hsueh- play ballstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $$$n$$$ white balls and $$$m$$$ black balls in the box.

Hsueh- randomly takes out a single ball from the box every time until the box is empty.

You need to calculate the probability $$$p$$$ of the number of white balls and black balls outside the box is equal at least once in the process.

You need to output answer modulo $$$998244353$$$. Formally, let $$$M = 998244353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.

For instance, we consider $$$n = 1$$$ and $$$m = 3$$$, and we appointed "w" to represent the white ball and "b" to represent the black ball.

There are $$$4$$$ possible outcomes:

  • "wbbb"
  • "bwbb"
  • "bbwb"
  • "bbbw"

Obviously, two of the results are legal, so the answer should be $$$\displaystyle \frac{1}{2}$$$, and we can get $$$\displaystyle \frac{1}{2} \equiv 499122177 \pmod {998244353}$$$.

Input

There are several test cases.

The first line contains a single integer $$$T(1 \leq T \leq 10^5)$$$, denoting the number of test cases. Then follow all the test cases.

For each test case, the first line contains two integers $$$n, m(1 \leq n, m \leq 10^6)$$$, representing $$$n$$$ white balls and $$$m$$$ black balls in box.

Output

For each test case, print a single integer in one line: the probability $$$p$$$ of the number of white balls and black balls outside the box is equal at least once in the process.

ExamplesInput
2
1 1
1 3
Output
1
499122177
Input
1
20 18
Output
893166001

加入题单

上一题 下一题 算法标签: