import strutils,sequtils,tables,math
let
 n=stdin.readline.parseInt
 a=stdin.readline.split.map(parseInt)
 q=stdin.readline.parseInt
var
 ac=a.toCountTable()
 ans=a.sum()
for i in 1..q:
 let
  bc=stdin.readline.split.map(parseInt)
  (b,c)=(bc[0],bc[1])
 ans+=(bc[1]-bc[0])*ac[bc[0]]
 ac[bc[1]]=ac[bc[1]]+ac[bc[0]]
 ac[bc[0]]=0
 echo ans