Mathematical Final Boss is getting tired from all his success and decided to start playing with some integer sequences.
After a while, he found a very interesting function which he called . For a sequence of numbers , he takes the non-increasing sorted sequence and stars to alternatively add and substract numbers.
Formally if the sorted sequence is , we have
.
This is too easy for our Final Boss, so, for a sequence of numbers he now wants to compute the sum of the values for all its subsets.
Now every morning he takes an integer sequence with numbers and queries that ask for the sum of all subsets of numbers of the substring .
He can do all these computations in less than a second and he is now curious if you can do it too with the help of a modern computer.
Because the numbers can become very large, you have to compute it modulo .
Input data
First line will contain one integer , - the length of the sequence.
The second line will contain numbers - the elements of the sequence.
The third line contains , - the number of queries.
The following lines each have a pair of numbers denoting the query interval.
Output data
The -th line will represent the answer to the -th query given by the Final Boss.
Constraints and clarifications
- For points, it is guaranteed that and .
- For the other points, we have and .
Example
stdin
5
5 4 3 2 1
3
2 3
1 5
2 2
stdout
8
80
4
Explanation
For the first query, we have the substring , with the subsets .
We have , and .
The answer for this query is .