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

ans=[]

for i in B:
  b=i[0]
  c=i[1]
  A=[i if i!=b else c for i in A ]
  
  ans.append(sum(A))
  
for i in ans:
  print(i)
  
