Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*<sub class="lower-index">1</sub>, the second one is at *a*<sub class="lower-index">2</sub>, the last one is at *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">1</sub> ≤ *a*<sub class="lower-index">2</sub> ≤ ... ≤ *a*<sub class="lower-index">*n*</sub>). 

Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w*<sub class="lower-index">*i*</sub> and height *h*<sub class="lower-index">*i*</sub>. Dima throws each box vertically down on the first *w*<sub class="lower-index">*i*</sub> stairs of the staircase, that is, the box covers stairs with numbers 1, 2, ..., *w*<sub class="lower-index">*i*</sub>. Each thrown box flies vertically down until at least one of the two following events happen:
 -  the bottom of the box touches the top of a stair; -  the bottom of the box touches the top of a box, thrown earlier. 
We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn't taken into consideration. Specifically, that implies that a box with width *w*<sub class="lower-index">*i*</sub> cannot touch the stair number *w*<sub class="lower-index">*i*</sub> + 1.

You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>; *a*<sub class="lower-index">*i*</sub> ≤ *a*<sub class="lower-index">*i* + 1</sub>).

The next line contains integer *m* (1 ≤ *m* ≤ 10<sup class="upper-index">5</sup>) — the number of boxes. Each of the following *m* lines contains a pair of integers *w*<sub class="lower-index">*i*</sub>, *h*<sub class="lower-index">*i*</sub> (1 ≤ *w*<sub class="lower-index">*i*</sub> ≤ *n*; 1 ≤ *h*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>) — the size of the *i*-th thrown box.

The numbers in the lines are separated by spaces.
n=int(input())
arr=[int(i) for i in input().split()]
arr.insert(0,0)
m=int(input())
last=1
for _ in range(m):
    a,b=map(int,input().split())
    if a>=last:
        print(arr[a])
        arr[a]+=b
        last=a
    else:
        print(arr[last])
        
