N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]

for q in range(Q):
  for n in range(N):
    if A[n] == S[q][0]:
      A[n] = S[q][1]
  print(sum(A))