import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
S = [0]*Q

for i, bc in enumerate(BC):
  b = bc[0]
  c = bc[1]
  s = 0
  a[a == b] = c
  S[i] = a.sum()

[print(i) for i in S]