N = int(input())
A = list(map(int, input().split()))
Q = int(input())
dict_A = {}
for a in A:
    if a in dict_A:
        dict_A[a] += 1
    else:
        dict_A[a] = 1
ans = sum(A)
# print(dict_A)
for i in range(Q):
    b, c = map(int, input().split())
    if b in dict_A.keys():
        ans += (c-b)*dict_A[b]
        if c not in dict_A.keys():
            dict_A[c] = dict_A[b]
            dict_A[b] = 0
        else:
            dict_A[c] += dict_A[b]
    print(ans)
