N = int(input())
A = list(map(int, input().split(' ')))
Q = int(input())
Bs = []
for i in range(Q):
    Bs.append(list(map(int, input().split(' '))))
    
    
A_list = [0]*(10**5+1)
for i in A:
    A_list[i] += 1
    
for B in Bs:
    b, c = B
    A_list[c] += A_list[b]
    A_list[b] = 0
    print(sum([i*num for num, i in enumerate(A_list)]))