import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
b, c = map(int, input().split())
BC = [b,c]
for i in range(Q - 1):
    b, c = map(int, input().split())
    BC = np.vstack((BC,[b,c]))

S = np.sum(A)
for i in range(Q):
    num = 0
    swap_mae = BC[i,0]
    swap_go = BC[i,1]
    for j in range(N):
        if A[j] == swap_mae:
            A[j] = swap_go
            num += 1
    S += (swap_go-swap_mae) * num
    print(S)
