409427: GYM103540 A I will win

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

Description

A. I will wintime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Your participating a tournament. The tournament consists of $$$n$$$ games. Your probability to win a game is $$$\frac{p}{q}$$$. Initially your rank in the tournament is $$$n+1$$$. If you win a game your rank will decrease by 1. If you lose a game, you rank will increase by 1. What is the probability that you will win the tournament (i.e. your rank will be 1)? Print answer modulo $$$10^9 + 7$$$.

Input

The first line contains one integer $$$T (1 \leq T \leq 2 \cdot 10^5)$$$ — number of testcases.

Each of the next $$$T$$$ lines contain three integers — $$$n, p, q$$$ $$$(1 \leq n, p, q \leq 10^{18})$$$, $$$(p \leq q)$$$.

Output

For each test case print your probability of winning the tournament. If it is $$$\frac{x}{y}$$$ print $$$x \cdot y^{-1}$$$ modulo $$$10^9 + 7$$$.

ExampleInput
4
10000 1 1
1000000000000000000 2 2
2 1 2
1000000000000000000 900000000000000000 1000000000000000000
Output
1
1
250000002
100777456
Note

In the first test case, you will win every game, so answer is 1.

In the second test case, probability is $$$\frac{1}{4}$$$. So the answer will $$$1 \cdot 4^{-1}$$$ modulo $$$10^9 + 7$$$. Modular inverse of $$$4$$$ (mod $$$10000007$$$) is $$$2500002$$$. So the answer is $$$2500002$$$.

Source/Category

加入题单

算法标签: