package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
func nextInt() int64{
  sc.Scan()
  i, e :=strconv.ParseInt(sc.Text(), 0, 64)
  if e!=nil{
    panic(e)
  }
  return i
}
func main(){
  var i, j, n, q int64
  sc.Split(bufio.ScanWords)
  n=nextInt()
  a:=make([]int64, n)
  for i=0;i<n;i++{
    a[i]=nextInt()
  }
  q=nextInt()
  b:=make([]int64, q)
  c:=make([]int64, q)
  ans:=make([]int64, q)
  for j=0;j<q;j++{
    fmt.Scan(&b[j], &c[j])
    for i=0;i<n;i++{
      if a[i]==b[j]{
        a[i]=c[j]
      }
      ans[j]+=a[i]
    }
  }
  for i=0;i<q;i++{
    fmt.Println(ans[i])
  }
}
