N = int(input())
A = list(map(int, input().split()))
dic = {}

for i in range(100000):
  dic[i] = A.count(i)
    
Q = int(input())

base = sum(A)

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