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):
    for j in range(n):
        if A[j] > lst[i][0]:
            break
        elif A[j] == lst[i][0]:
            A[j] = lst[i][1]
    print(sum(A))
    A = sorted(A)