N = int(input())

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

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