N = int(input())
A = list(map(int, input().split()))
A.sort()
Q = int(input())
BC = []

def my_index(l, x, default=N):
    if x in l:
        return l.index(x)
    else:
        return default

for i in range(Q):
  BC.append(list(map(int, input().split())))

for i in range(Q):
  for j in range(my_index(A, BC[i][0]), N):
    if A[j] == BC[i][0]:
      A[j] = BC[i][1]
    else:
      break
  print(sum(A))