#D - Replacing
import collections
N= int(input())
A= list(map(int,input().split()))
Q = int(input())
B = [list(map(int,input().split())) for i in range(Q)]

A.sort()
sub = 0
ans = sum(A)

for i in range(Q):
    if A.count(B[i][0]) > 0:
        #for j in range(A.count(B[i][0])):
        ans = ans +(B[i][1] - B[i][0])*A.count(B[i][0])
        for j in range(N):
            if A[j] == B[i][0]:
                A[j] = B[i][1]
            elif A[j] > B[i][0]:
                break
            else:
                pass
        print(ans)

    else:
        print(ans)