n = int(input())
a = list(map(int,input().split()))
n = len(a)
q = int(input())

for i in range(q):
  a.sort()
  b,c = map(int,input().split())
  for i in range(n):
    if a[i] == b:
      a[i] = c
    elif a[i] > b:
      break
  print(sum(a))
  