#P10978. [2015杭电多校]The sum of gcd

[2015杭电多校]The sum of gcd

The sum of gcd

Problem Description

You have an array AA,the length of AA is nn Let $f(l,r)=\sum_{i=l}^{r}\sum_{j=i}^{r}gcd(a_i,a_{i+1}....a_{j})$

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case: First line has one integers nn Second line has nn integers AiA_i Third line has one integers QQ,the number of questions Next there are Q lines,each line has two integers ll,rr 1T31\leq T \leq 3 1n,Q1041\leq n,Q \leq 10^4 1ai1091\leq a_i \leq 10^9 1l<rn1\leq l<r \leq n

Output

For each question,you need to print f(l,r)f(l,r)

Sample Input

2
5
1 2 3 4 5
3
1 3
2 3
1 4
4
4 2 6 9
3
1 3
2 4
2 3

Sample Output

9
6
16
18
23
10

Author

SXYZ

Source

2015 Multi-University Training Contest 8