N = int(input()) 
A = list(int(i) for i in input().split())  
Q = int(input()) 
B_C = [[int(i) for i in input().split()] for i in range(Q)] 
for j in range(Q):
  #print(j)
  A = [B_C[j][1] if i == B_C[j][0] else i for i in A]
  print(sum(A))