A function is defined by the following recurrence relations:
, if is even
, if is odd
where and
You have to answer multiple queries. In each query, you are given two integers and and you are required to determine the value of .
is fixed for all queries.
Input format
First line: Two integers and , where represents the number of queries
Each of the next lines: Two integers and
Output format
For each query, print the value of in a new line.
As 3 is odd, f(3) = 3 * f(1) = 3 * 1 = 3
As 4 is even, f(4) = 2*f(3) - f(2) + 2 = 2*3 - 1 + 2 = 7
So, when L is 3, R is 4 and P is 100000007, answer is (3 + 7)%100000007 = 10
Similarly, when L is 4, R is 4 and P is 100000007, answer is (7) %100000007 = 7