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):
  list_a=[list_b[i][1] if k==list_b[i][0] else k for k in list_a]
  print(sum(list_a))