N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int,input().split())) for i in range(Q)]
for i in B:
    for j in range(len(A)):
        if A[j] > i[0]:
            break
        if A[j] == i[0]:
            A[j] = i[1]
    print(sum(A))