n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
b_list = [list(map(int, input().split())) for _ in range(q)]
 
j = 0
while j < q:
  a_list = [b_list[j][1] if i == b_list[j][0] else i for i in a_list]
  s = sum(a_list)
  print(s)
  j += 1