n=int(input())
A=list(map(int, input().split()))

q=int(input())
BC=[list(map(int,list(input().split()))) for _ in range(q)]

for i in range(q):
  for j in range(n):
    if A[j]==BC[i][0]:
      A[j]=BC[i][1]
  print(sum(A))