import numpy as np
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0 for _ in range(Q)]
C = [0 for _ in range(Q)]
for i in range(Q):
  B[i], C[i] = map(int, input().split())
  
for i in range(Q):
  for j in range(N):
    if A[j] == B[i]:
      A[j] = C[i]
  print(np.sum(A))