HeHe

Accepts: 16
Submissions: 89
Time Limit: 5000/3000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
$$M = \begin{pmatrix} t_{n-1} & t_n & t_{n+1} & \cdots & t_{2*n-3} & t_{2*n-2}\\ t_{n-2} & t_{n-1} & t_n & \cdots & t_{2*n-4} & t_{2*n-3}\\ t_{n-3} & t_{n-2} & t_{n-1} & \cdots & t_{2*n-5} & t_{2*n-4}\\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots\\ t_1 & t_2 & t_3 & \cdots & t_{n-1} & t_n\\ t_0 & t_1 & t_2 & \cdots & t_{n-2} & t_{n-1}\\ \end{pmatrix}$$ You are expected to write a program to point out some elements of $M*M$.
Input
Multi test cases (about 100), every case occupies two lines. The first line contains an integer n. Then second line contain 2*n-1 integers $t_0, t_1, t_2, t_3, \ldots, t_{2*n-4}, t_{2*n-3}, t_{2*n-2}$ separated by exact one space. The third line contains an integer m, indicates the number of query. Next m lines will give queries $\begin{matrix} r_0 & c_0\\ r_1 & c_1\\ r_2 & c_2\\ \vdots & \vdots\\ r_{m-1} & c_{m-1} \end{matrix}$ For $r_0, c_0$ the program will query the element of $M*M$ which locates in the $r_0^{th}$ row, $c_0^{th}$ column. For $r_i, c_i(0
Output
For each case£Ĵoutput the sum of the answer of each query.
Sample Input
3
1 2 3 1 2
2
0 0
1 2
4
10 5 7 2 10 5 7
3
1 2
3 0
2 1
2
1 2 3
4
0 0
0 1
1 0
1 1
Sample Output
23
348
22
Hint
$\quad\ \text{For the first case }M = \begin{pmatrix} 3 & 1 & 2\\ 2 & 3 & 1\\ 1 & 2 & 3 \end{pmatrix}$ $\text{For the second case }M = \begin{pmatrix} 2 & 10 & 5 & 7\\ 7 & 2 & 10 & 5\\ 5 & 7 & 2 & 10\\ 10 & 5 & 7 & 2 \end{pmatrix}$