import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
B = []
C = []
for i in range(Q):
    BTemp,CTemp = map(int, input().split())
    B.append(BTemp)
    C.append(CTemp)
for BTemp,CTemp in zip(B,C):
    A = np.where(A == BTemp, CTemp, A)
    print(sum(A))
