import numpy as np
N = int(input())
lis = np.array(list(map(int, input().split())), dtype = int)
Q = int(input())

for _ in range(Q):
  B, C = map(int, input().split())
  lis[lis == B] = C
  print(sum(lis))
