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