#564. 「Nowcoder多校 2019 Day2」Eddy Walker

「Nowcoder多校 2019 Day2」Eddy Walker

题目描述

Eddy likes to walk around. Especially, he likes to walk in a loop called "Infinite loop". But, actually, it's just a loop with finite length(Anyway, the name doesn't matter). Eddy can walk in a fixed length. He finds that it takes him N steps to walk through the loop a cycle. Then, he puts N marks on the "Infinite loop" labeled with 0,1,,N1 0,1,…,N−1 , where i and i+1 are a step away each other, so as 0 and N-1. After that, Eddy stands on the mark labeled 0 and start walking around. For each step, Eddy will independently uniformly randomly choose to move forward or backward. If currently Eddy is on the mark labeled i, he will on the mark labeled i+1 if move forward or i-1 if move backward. If Eddy is on the mark labeled N-1 and moves forward, he will stand on the mark labeled 0. If Eddy is on the mark labeled 0 and moves backward, he will stand on the mark labeled N-1.

Although, Eddy likes to walk around. He will get bored after he reaches each mark at least once. After that, Eddy will pick up all the marks, go back to work and stop walking around.

You, somehow, notice the weird convention Eddy is doing. And, you record T scenarios that Eddy walks around. For i-th scenario, you record two numbers NiN_iNi​, MiM_iMi​, where NiN_iNi​ tells that in the i-th scenario, Eddy can walk through the loop a cycle in exactly NiN_iNi​ steps(Yes! Eddy can walk in different fixed length for different day.). While MiM_iMi​ tells that you found that in the i-th scenario, after Eddy stands on the mark labeled MiM_iMi​, he reached all the marks.

However, when you review your records, you are not sure whether the data is correct or even possible. Thus, you want to know the probability that those scenarios will happen. Precisely, you are going to compute the probability that first i scenarios will happen sequentially for each i.

$\textbf{Precisely, you are going to compute the probability that first i scenarios will happen sequentially for each i.}$

输入格式

The first line of input contains an integers T. Following T lines each contains two space-separated integers NiN_i​ and MiM_i.

输出格式

Output T lines each contains an integer representing the probability that first i scenarios will happen sequentially. you should output the number module 109+7(1000000007)10^9+7(1000000007). Suppose the probability is P/QP/Q​, the desired output will be P×Q1mod  1e9+7P×Q^-1mod  1e9+7

样例

样例输入 1

3
1 0
2 1
3 0

样例输出 1

1
1
0

数据范围与提示

1T10211≤T≤1021

0Mi<Ni1090≤Mi​<Ni​≤109