import collections

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for _ in range(Q)]

ans = sum(A)

for i in range(Q):
    counter = collections.Counter(A)
    if BC[i][0] in counter:
        ans += counter[BC[i][0]]*(BC[i][1]-BC[i][0])
        print(ans)
        A = [BC[i][1] if x==BC[i][0] else x for x in A]
    else:
        print(ans)