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
a_replace = a_list
while j < q:
  a_replace = [b_list[j][1] if i == b_list[j][0] else i for i in a_replace]
  s = sum(a_replace)
  print(s)
  j += 1