N = int(input())
num_list = list(map(int,input().split()))
q = int(input())

for i in range(q):
  query = list(map(int,input().split()))
  for j in range(len(num_list)):
    if num_list[j] == query[0]:
      num_list[j] = query[1]
  print(sum(num_list))