n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
q = int(input())
lst = [0] * q
for i in range(q):
    lst[i] = list(map(int, input().split()))
for i in range(q):

    pl = 0
    pr = len(A) - 1

    while True:
        pc = (pl + pr)//2
        if A[pc] == lst[i][0]:
            b = 0
            c = 0
            while A[pc+b] == lst[i][0]:
                A[pc+b] = lst[i][1]
                b += 1
                if pc + b == len(A):
                    break
            while A[pc+c] == lst[i][0]:
                A[pc+c] = lst[i][1]
                c -= 1
                if pc + c == 0:
                    break
        elif A[pc] < lst[i][0]:
            pl = pc + 1
        else:
            pr = pc -1
        if pl > pr:
            break
    
    print(sum(A))
    A = sorted(A)