N = int(input())
A = list(map(int, input().split()))
Q = int(input())
A = sorted(A)

def binarySearch(array, key):
    l = 0
    r = N - 1
    pos = -1
    while l <= r and pos == -1:
        m = (l + r) // 2
        m_val = array[m]
        if m_val == key:
            pos = m
        elif m_val > key:
            r = m - 1
        else:
            l = m + 1
    return pos

def upperIdx(array, pos):
    if pos == N - 1:
        return pos
    else:
        while(array[pos] == array[pos + 1]):
            if pos >= N - 2:
                break
            else:
                pos += 1
        if array[pos] == array[N - 1]:
            pos += 1 
        return pos

def lowerIdx(array, pos):
    if pos == 0:
        return pos
    else:
        while(array[pos] == array[pos - 1]):
            if pos <= 1:
                break
            else:
                pos -= 1
        if array[pos] == array[0]:
            pos -= 1
        return pos

for i in range(Q):
    A = sorted(A)
    Bi, Ci = map(int, input().split())
    position = binarySearch(A, Bi)
    if position == -1:
        print(sum(A))
    else:
        lower = lowerIdx(A, position)
        upper = upperIdx(A, position)
        C = [Ci] * (upper - lower + 1)
        A[lower:upper + 1] = C
        print(sum(A))