Task
For some , we say that the sequence of integers is good if is divisible by for every from to .
You are given an integer sequence of length and queries of the form , which represent the range of values from the sequence.
For each query compute the number of subintervals of the given range which are good sequences (each subinterval is considered as an independent sequence, indexed from ).
Input data
The first line of the input file contains a single integer , the number of test cases. test cases follow, each preceded by an empty line.
The first line of each test case contains a single integer , the length of the sequence.
The second line of each test case contains space-separated integers , the elements of the sequence.
The third line of each test case contains a single integer , the number of queries.
Each of the following lines contain two integers , the query intervals.
Output data
For each test case, output all query results, each on a separate line.
Constraints and clarifications
- .
- .
- .
- .
- The sum of and over all test cases does not exceed .
# | Points | Constraints |
---|---|---|
1 | 0 | Examples. |
2 | 10 | |
3 | 20 | |
4 | 30 | for every |
5 | 40 | No additional limitations. |
Example
stdin
1
5
6 24 6 8 10
3
1 3
2 4
1 5
stdout
6
5
12
Explanation
In the sample case, consider the the second query corresponding to the range of values .
- An example of a good subinterval is , because is divisible by and is divisible by .
- An example of a subinterval which is not good is , as is not divisible by .
The good subintervals for this query are the sequences , , , and .