package main

import (
	"fmt"
	"sort"
)

func main() {
	var num int
	var quant int
	fmt.Scan(&num)
	var tmpNum int
	hash := make([]int, 100000)
	for i := 0; i < num; i++ {
		fmt.Scan(&tmpNum)
		hash[tmpNum]++
	}
	sum := 0
	for key, value := range hash {
		sum += key * value
	}
	fmt.Scan(&quant)
	qa := make([][]int, quant)
	for i := 0; i < quant; i++ {
		tmp := scanNums(2)
		qa[i] = tmp
		def1 := tmp[0] * hash[tmp[0]]
		def2 := tmp[1] * hash[tmp[1]]
		sum = sum + def2 - def1
		hash[tmp[0]], hash[tmp[1]] = 0, hash[tmp[0]]+hash[tmp[0]]
		fmt.Println(sum)
	}
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}
