import bisect
N = int(input())
a = list(map(int,input().split()))
q = int(input())
sum_a = 0
output = 0
cnt = 0
a.sort()

for i in range(q):
  bc = list(map(int,input().split()))
  flag = False
  try:
    nn = a.index(bc[0])
    for j in range(nn-1, len(a)):
      if a[j] == bc[0]:
        a[j] = bc[1]
        flag = True
      else:
        if flag == True:
          break
  except ValueError:
    pass
  print(sum(a))
  a.sort()


  
  