n = int(input())
a_list = list(map(int, input().split()))
q = int(input())



def replace_seq(key):
  if key not in query_dict:
    return key
  else:
    return query_dict[key]

for i in range(q):
  b, c = map(int, input().split())
  query_dict = {}
  query_dict[b] = c
  a_list = [replace_seq(a) for a in a_list]
  print(sum(a_list))




