from collections import Counter, deque
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
L = deque()
for _ in range(Q):
    b, c = map(int, input().split())
    L.append([b, c])
d = Counter(A)
sum_a = sum(A)
for j in range(Q):
    brep = d[L[j][0]]
    sum_a -= L[j][0] * brep
    if (d[L[j][1]]):
        d[L[j][1]] += brep
        d[L[j][0]] -= brep
    else:

        d[L[j][1]] = brep
    sum_a += L[j][1] * brep

    print(sum_a)
