Alin wants to start a new life as a farmer in the countryside of Sălaj. He has planted a row of pear trees, numbered from to in the order in which they were planted. The pear tree () has flowers. Now he is thinking about pollinating the trees by releasing some bees.
Alin studies scenarios in which pollination can take place. For each scenario ():
- he chooses an interval [, ];
- releases the bees at the pear tree;
- the bees will then visit all pear trees to the right, in order, up to the pear tree, including .
The Sălaj pear trees have a special way of interacting with bees:
- if the number of flowers in the currently visited tree, call that number , has the same parity as the number of flowers in the previous tree, call that number , then the number of flowers in the current tree will increase to ;
- otherwise, the current tree will bloom new flowers, increasing its total to .
For each scenario (), Alin wants to know the number of flowers in the -th pear tree at the end of the pollination for this scenario. Since this number may be very large, output it modulo .
Task
Given the number of flowers for each pear tree, compute the result for each scenario modulo .
Input data
The first line of the input contains the integer - the number of pear trees.
The second line of the input contains integers separated by spaces - the number of flowers in each pear tree.
The third line of the input contains the integer - the number of scenarios.
Each of the next lines contain space-separated integers - and - the left and right ends for the interval of trees that will be pollinated in the -th scenario.
Output data
The output will contain lines. On line (), the result for scenario will be printed.
Constraints and clarifications
- for .
- for .
- All scenarios are independent
| # | Score | Constraints |
|---|---|---|
| 0 | 0 | Examples |
| 1 | 13 | $N, Q \leq 1 \ 000 |
| 2 | 14 | |
| 3 | 8 | |
| 4 | 9 | The number of flowers in each pear tree has the same parity. |
| 5 | 56 | No further restrictions. |
Example 1
stdin
5
4 2 5 7 8
3
1 3
4 5
1 5
stdout
13
15
99
Explanation
For the first example, each scenario goes as follows:
Example 2
stdin
3
100000 100000 100000
1
1 3
stdout
733427426
Explanation
For the second example, the answer is , which modulo is equal to .