from collections import defaultdict

N = int(raw_input())
A = map(int, raw_input().split())

lookup = defaultdict(int)
for a in A:
  lookup[a] += 1
  
cur_sum = 0
for k in lookup:
  cur_sum += k*lookup[k]
  
Q = int(raw_input())
for q in xrange(Q):
  b, c = map(int, raw_input().split())
  cur_sum -= b*lookup[b]
  cur_sum += c*lookup[b]
  
  lookup[c] += lookup[b]
  lookup[b] = 0
  
  print cur_sum