package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		b := nextInt()
		c := nextInt()

		r := 0
		for k, v := range a {
			if v == b {
				v = c
				a[k] = c
			}

			r += v
		}
		fmt.Println(r)
	}

}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
