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

dic = {}
for i in range(100000):
  if List[i] != 0:
    dic[i+1] = List[i]



tmp = 0
for i in range(Q):
  B,C= map(int, input().split())
  if B in dic:
    tmp = dic[B]
  else:
    print(ans)
    continue
  ans = ans + tmp*(C-B) 
  print(ans)
  if C in dic:
    dic[C] += tmp
  else:
    dic.pop(B)
    dic[C] = tmp