from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
Q = int(input())
S = []
for i in range(Q):
    B, C = list(map(int, input().split()))
    A[B], A[C] = 0, A[C]+A[B]
    s = sum([k*v for k, v in A.items()])
    S.append(s)
for s in S:
    print(s)