As Christmas approaches, things become very busy at the North Pole. The elves, Santa's main workforce, have an infinitely long conveyor belt divided into slots. Initially, there is only one gift on the conveyor belt, located at position . To determine the number of gifts in slot , Bahoi, Santa's chief executive, will move the conveyor belt one position to the right, adding the number of gifts from position (after the move) to the number of gifts from position (before the move).
In other words, if is the number of gifts in slot , then , for any .
Task
Due to the chaos at the North Pole, chief executive Bahoi wants to verify if he has correctly calculated the number of gifts in each slot. Thus, he asks himself questions, each question being in the form: what is the total number of gifts in the slots between and ? Due to his busy schedule, he considers it sufficient to find the remainder of the total number of gifts when divided by .
Input data
The first line contains the number and the next lines contain 3 numbers each, representing , , and .
Output data
On line of the output, you will find the answer to the question number .
Constraints and clarifications
- We will consider that there are no gifts at position .
- For points, and .
Example
stdin
3
0 5 1000
1 3 1000000007
8 8 18
stdout
12
4
3
Explanation
For instance, for the first query, the total number of gifts in slots to is , and is . For the second query, the total number of gifts in slots to is , and is . For the third query, the number of gifts in slot is , and is .