
n = int(input())
A = list(map(int,input().split()))
q = int(input())

from collections import Counter
co = list(Counter(A).items())
co = [list(_) for _ in co]
#print(co)
num = len(co)

total = sum(A)
for i in range(q):
    b, c = map(int,input().split())
    for j in range(num):
        if co[j][0] == b:
            total -= (co[j][0] * co[j][1])
            co[j][0] = c
            total += (co[j][0] * co[j][1])
    print(total)
