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

for j in range(Q):
  A = [L[j][1] if i == L[j][0] else i for i in A]
  print(sum(A))