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_)
  

#for i in range(Q):
  #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])