from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
A = Counter(A)
bc = [tuple(map(int, input().split())) for i in range(Q)]

ans = 0
for b, c in bc:
    v = A.pop(b, None)
    if v:
        A[c] += v
    ans = 0
    ans = sum(i*j for i, j in A.items())
    print(ans)