N = int(input())

str1 = input()
A = [int(str1.split(" ")[i]) for i in range(N)]
  
Q = int(input())

for j in range(Q):
  str2 = input()
  B, C = int(str2.split(" ")[0]), int(str2.split(" ")[1])
  A = [C if a == B else a for a in A]
  print(sum(A))