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
  for j in range(len(a)):
    if a[j] == bc[i][0]:
      a[j] = bc[i][1]
      flag = True
    else:
      if flag == True:
        break
  print(sum(a))
  a.sort()

  
  