import collections

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
Q = int(input())
X = [[] for _ in range(Q)]
for i in range(Q):
    X[i] = list(map(int, input().split()))

for i in range(Q):
    b, c = X[i]
    for j in range(C[b]):
        A.remove(b)
        A.append(c)
    C = collections.Counter(A)
    print(sum(A))