import numpy as np

n = int(input())
a = input().split()
np_a=np.array(a, dtype=int)

sum=np.int(sum(np_a))
count=np.zeros(100001, dtype='int64')
for i in range(0,n):
  count[np_a[i]]+= 1
  
change=np.array(range(100001))

q = int(input())
for i in range(0,q):
  b, c= map(int, input().split())
  count[c]=count[c]+count[b]
  sum=sum+(c-b)*count[b]
  
  print (sum)
