## Query

Time Limit: 5 sec
Memory Limit: 64 MB
Attempts: 0
Accuracy: 0.00%
Author: Akashdeep Goel

Digo has a Biology exam. The paper has N questions. All the questions have integral marks. Digo has M friends who are sitting around him in a circle. Digoâ€™s friends are numbered from 1 to M, in a clockwise order. Each friend solves exactly one question, not necessarily distinct.

Digo can select any index i (1 <= i <= M) and a number j, and then copies the answers of his j friends starting from index i, (in the clockwise order). If Digo attempts the same question twice, he will get marks only once. Given i and j, your task is to determine what will be the marks scored by Digo.

Input

First line contains N, the number of questions.

Next line contains N space separated integers, where ith integer denotes the marks of the ith question.

Each question will contain atmost 100 marks.

Next line contains an integer M, the number of friends of Digo.

Next line contains M space separated integers, where ith integer denotes the question solved by ith friend.

The next line contains Q, which is the number of queries asked by Digo.

The next Q lines contain one pair of integers (i, j) each, where i denotes the starting index, and j denotes the number of friends from which he copies the answers.

Output

For every query print a single integer, the marks scored by Digo in that query.

Constraints

1 <= N <= 10000

1 <= M <= 100000

1 <= Q <= 10000

1 <= i, j <= N

Example

Sample Input

3

1 2 3

5

1 1 2 1 3

3

1 5

2 3

5 2

Sample Output

6

3

4

ID

SUBMITTED AT

STATUS

LANGUAGE

TIME

MEMORY USED

USER

TIME

STATUS

LANGUAGE

TIME

MEMORY USED