Fraction Reduction

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

Chiaki has a fraction ab\frac{a}{b} (not necessary an irreducible fraction) and can perform the following 22 operations:

  • If the current fraction is xx, Chiaki can change it to 1x-\frac{1}{x}.
  • If the current fraction is xx, Chiaki can change it to x+1x+1.

Now, Chiaki would like to know the number of minimum operations needed to make ab\frac{a}{b} become 00. Since this number may be very large, you are only asked to calculate it modulo 109+710^9+7.

입력

There are multiple test cases. The first line of the input contains an integer TT (1T1051 \le T \le 10^5), indicating the number of test cases. For each test case:

The first line contains two integers aa and bb (1018a1018,1b1018-10^{18} \le a \le 10^{18}, 1 \le b \le 10^{18}), denoting the fraction.

출력

For each test case, output an integer denoting the the number of minimum operations modulo 109+710^9+7, or 1-1 if there's no such operations to make ab\frac{a}{b} become 00.

힌트

For the 11-st sample, you don't need any operations.

For the 22-nd sample, one possible sequence is: 11110\frac{1}{1} \to -\frac{1}{1} \to 0.

For the 33-rd sample, one possible sequence is: 121221110-\frac{1}{2} \to \frac{1}{2} \to -\frac{2}{1} \to -\frac{1}{1} \to 0.

For the 44-th sample, one possible sequence is: 242442220-\frac{2}{4} \to \frac{2}{4} \to -\frac{4}{2} \to -\frac{2}{2} \to 0.

For the 55-th sample, one possible sequence is: 855838835323133121110\frac{8}{5} \to -\frac{5}{8} \to \frac{3}{8} \to -\frac{8}{3} \to -\frac{5}{3} \to -\frac{2}{3} \to \frac{1}{3} \to -\frac{3}{1} \to -\frac{2}{1} \to -\frac{1}{1} \to 0.