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

  
  