array = [0 for i in range(11)]
N = int(input())
A = list(map(int, input().split()))
for a in A:
    array[a] += 1

souwa = sum(A)
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    souwa = souwa + (C-B)*array[B]
    array[C] += array[B]
    array[B] = 0
    print(souwa)
