human
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an). 

Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws each box vertically down on the first wi stairs of the staircase, that is, the box covers stairs with numbers 1, 2, ..., wi. 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 wi cannot touch the stair number wi + 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.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of n integers, a1, a2, ..., an (1 ≤ ai ≤ 109.
ai ≤ ai + 1).

The next line contains integer m (1 ≤ m ≤ 105) — the number of boxes. Each of the following m lines contains a pair of integers wi, hi (1 ≤ wi ≤ n.
1 ≤ hi ≤ 109) — the size of the i-th thrown box.

The numbers in the lines are separated by spaces.

Output

Print m integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

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

Output

1
3
4
6

Input

3
1 2 3
2
1 1
3...
from
assistant
#Here is Python program to determine how high the bottom of the box after landing will be.
sys import stdin
from math import *

rints = lambda: [int(x) for x in stdin.readline().split()]

class range_quary:
    def __init__(self, arr, n):
        self.tree, self.n, self.lazy, self.h = [0] * (2 * n), n, [0] * (n), int(ceil(log(n, 2)))
        # build tree
        if arr:
            for i in range(2 * n - 1, 0, -1):
                if i >= n:
                    self.tree[i] = arr[i - n]
                else:
                    self.tree[i] = max(self.tree[i << 1], self.tree[(i << 1) + 1])

    def apply(self, p, val, children):
        self.tree[p] = val

        if p < self.n:
            self.lazy[p] = val

    # fix applied nodes and down nodes
    def build(self, p):
        children = 1
        while p > 1:
            p >>= 1
            children <<= 1
            self.tree[p] = max(self.tree[p << 1], self.tree[(p << 1) + 1], self.lazy[p])

    # push lazy operations
    def push(self, p):
        for s in range(self.h, 0, -1):
            i = p >> s
            if self.lazy[i]:
                children = 1 << (s - 1)
                self.apply(i * 2, self.lazy[i], children)
                self.apply(i * 2 + 1, self.lazy[i], children)

                self.lazy[i] = 0

    def update(self, l, r, val):
        l += self.n
        r += self.n
        l0, r0, children = l, r, 1

        while l < r:
            if l & 1:
                self.apply(l, val, children)
                l += 1

            if r & 1:
                r -= 1
                self.apply(r, val, children)

            l >>= 1
            r >>= 1
            children <<= 1
        self.build(l0)
        self.build(r0 - 1)

    def quary(self, l, r):
        l += self.n
        r += self.n

        # apply lazy nodes
        self.push(l)
        self.push(r - 1)
        res = 0

        while l < r:
            if l & 1:
                res = max(self.tree[l], res)
                l += 1
            if r & 1:
                r -= 1
                res = max(self.tree[r], res)

            l >>= 1
            r >>= 1
      ...