package main

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

var rd = bufio.NewReader(os.Stdin)

// 標準入力から1行読み込む。
func readLine() string {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := rd.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// 渡された文字列(空白区切りの整数の並び)をintのスライスにする。
func intsFromLine(line string) []int {
	slice := make([]int, 0, 1024)
	for _, str := range strings.Split(line, " ") {
		num, err := strconv.Atoi(str)
		if err != nil {
			panic(err)
		}
		slice = append(slice, num)
	}
	return slice
}

func main() {
	var n int
	fmt.Scan(&n)
	line := readLine()
	nums := intsFromLine(line)
	var q int
	line = readLine()
	fmt.Sscan(line, &q)

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	for i := 0; i < q; i++ {
		line = readLine()
		buf := intsFromLine(line)
		b, c := buf[0], buf[1]
		nums_new := make([]int, 0, 1)

		for m := 0; m < n; m++ {
			if nums[m] == b {
				nums_new = append(nums_new, c)
			} else {
				nums_new = append(nums_new, nums[m])
			}
		}
		nums = nums_new
		total := 0
		for j := 0; j < n; j++ {
			total += nums[j]
		}
		fmt.Fprintln(writer, total)
	}
}
