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 i in range(len(A)):
    sum += A[i] 

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