N = int(input())
lstA = [int(Ai) for Ai in input().split()]
Q = int(input())
for _ in range(Q):
  i = 0
  B,C = [int(w) for w in input().split()]
  for idx, val in enumerate(lstA):
    if val == B:
      lstA[idx] = C
  print(sum(lstA))