package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	am := make(map[int]int)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
		sum += as[i]
		am[as[i]]++
	}

	var q int
	fmt.Scan(&q)
	var b, c int
	for i := 0; i < q; i++ {
		fmt.Scan(&b, &c)
		p := am[b]
		am[c] += p
		sum -= b * p
		sum += c * p
		fmt.Println(sum)
	}
}
