N = int(input())
A_row = input().split(" ")
for i in range(len(A_row)):
  A_row[i] = int(A_row[i])
Q = int(input())
D = [0]*Q
for i in range(Q):
  D[i] = input().split(" ")
  B = int(D[i][0])
  C = int(D[i][1])
  
  for i in range(len(A_row)):
    if B == A_row[i]:
      A_row[i] = C
    else:
      None
  print(sum(A_row))