N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
list_list = []
for i in range(Q):
  list_ =  list(map(int, input().split()))
  list_list.append(list_)
  

yobi = [1]
for i in range(Q):
  if(len(list(set(A_list)))==1):
    if(A_list[0]==list_list[i][0]):
      yobi[0] = list_list[i][1]
      A_list = yobi*len(A_list)
      #print(A_list)
  else:
    for j in range(N):
      if(A_list[j] == list_list[i][0]):
        A_list[j] = list_list[i][1]
  print(sum(A_list))
  
  
  
#for i in range(Q):
  #sum_ = sum(A_list)
  #変更の個数
  #cosuu = A_list.count(list_list[i][0])
  #sa = list_list[i][1] - list_list[i][0]
  #henkou = sa*cosuu
  #print(sum_ + henkou)
  #for j in range(cosuu):
    #A_list.remove(list_list[i][0])
    #A_list.append(list_list[i][1])