package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	w       = bufio.NewWriter(os.Stdout)
)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func main() {
	scanner.Split(bufio.ScanWords)
	defer w.Flush()

	n := readInt()

	a := map[int]int{}
	for i := 0; i < n; i++ {
		j := readInt()
		a[j]++
	}

	q := readInt()
	for i := 0; i < q; i++ {
		b := readInt()
		c := readInt()
		tmp := a[b]
		a[b] = 0
		a[c] += tmp

		var total = 0
		for k, v := range a {
			total += k * v
		}
		fmt.Fprintln(w, total)
	}
}