N=int(input())
A=[int(x) for x in input().split()]
q=int(input())
for i in range(q):
  total=0
  b,c=map(int,input().split())
  A.remove(b)
  A.append(c)
  for j in range(len(A)):
    total+=A[j]
  print(total)  