nb=int(input())
liste = [int(x) for x in input().split()]
nba = int(input())
for loop in range(nba):
  n,r = map(int,input().split())
  for loop in range(len(liste)):
    if liste[loop]==n:
      liste[loop] = r
  print(sum(liste))
