package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()

	n := nextInt()
	m := map[int]int{}
	sum := 0
	for i := 0; i < n; i++ {
		tmp := nextInt()
		m[tmp]++
		sum += tmp
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		from := nextInt()
		to := nextInt()

		fromcnt := m[from]
		m[to] += fromcnt
		sum -= from * fromcnt
		sum += to * fromcnt

		fmt.Println(sum)
	}

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
