n=int(input())
list_a=list(map(int,input().split()))
k=int(input())
list_b= [list(map(int, input().split())) for _ in range(k)]
for i in range(k):
  for k in range(n):
    if list_a[k]==list_b[i][0]:
      list_a[k]=list_b[i][1]
  print(sum(list_a))