import numpy as np
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
P = np.array([list(map(int,input().split())) for i in range(Q)]).T
B = P[0]
C = P[1]

for i in range(len(B)):
    A=np.where(A==B[i],C[i],A)
    print(A.sum())