import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
P = [list(map(int,input().split())) for i in range(Q)]

A = np.array(A)

for item in P:
  np.place(A, A == item[0], item[1])
  print(np.sum(A))
