N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = 0

List = [0]*100000
for i in A:
  List[i-1] += 1
  ans += i

tmp = 0
for i in range(Q):
  B,C= map(int, input().split())
  tmp = List[B-1]
  ans = ans + tmp*(C-B) 
  print(ans)
  List[C-1] += tmp