N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]


#print(N)
#print(A)
#print(Q)
#print(x)
#print(y)

#取得完了

sum = sum(A)

#print(sum)

for i in range (Q):
  k = A.count(B[i])
  sum = sum + k * (C[i]-B[i])
  A.translate(str.maketrans(B[i]: C[i]))
  print(sum)