N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

for q in range(Q):
  b, c = list(map(int, input().split()))
  a_list = [c if x==b else x for x in a_list]
  print(sum(a_list))

