N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]


#print(N)
#print(A)
#print(Q)
#print(x)
#print(y)

#取得完了

#sum = sum(A)

#print(sum)

for i in range (Q):
  for j in range(N):
    if A[j] == B[i]:
      A[j] = C[i]
  print(sum(A))
