The Fibonacci sequence is defined by F0=0, F1=1, and Fn=Fn−1+Fn−2 for n≥2. It starts 0, 1, 1, 2, 3, 5, 8, 13, 21.
Solving the recurrence gives a closed form.
Fn=51{(21+5)n−(21−5)n}
The sequence has many properties. Two of them are the following.
∑i=1nFi=Fn+2−1,Fn∣Fkn(k=0,1,2,…)
This problem asks for the greatest common divisor of two Fibonacci numbers. Given two integers N and M, compute gcd(FN,FM). The value is huge, so print it modulo 109+7. Take the remainder after computing the greatest common divisor.
The first line contains the number of test cases T. (1≤T≤1000)
Each of the next T lines contains two integers N and M separated by one space. (0<N,M≤109)
For each test case, print gcd(FN,FM) modulo 109+7 on its own line.