N = int(input())

A = list(map(int,input().split()))

Q = int(input())

BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]

list = [0] * 100001
sum = 0
for i in range(100001):
    list[i] = A.count(i)

for j in range(N):
    sum += A[j] 

for k in range(Q):
    sum += list[B[k]] * (C[k] -B[k])
    list[C[k]] += list[B[k]]
    list[B[k]] = 0
    print(sum)