Chiaki has a fraction ba (not necessary an irreducible fraction) and can perform the following 2 operations:
Now, Chiaki would like to know the number of minimum operations needed to make ba become 0. Since this number may be very large, you are only asked to calculate it modulo 109+7.
There are multiple test cases. The first line of the input contains an integer T (1≤T≤105), indicating the number of test cases. For each test case:
The first line contains two integers a and b (−1018≤a≤1018,1≤b≤1018), denoting the fraction.
For each test case, output an integer denoting the the number of minimum operations modulo 109+7, or −1 if there's no such operations to make ba become 0.
For the 1-st sample, you don't need any operations.
For the 2-nd sample, one possible sequence is: 11→−11→0.
For the 3-rd sample, one possible sequence is: −21→21→−12→−11→0.
For the 4-th sample, one possible sequence is: −42→42→−24→−22→0.
For the 5-th sample, one possible sequence is: 58→−85→83→−38→−35→−32→31→−13→−12→−11→0.