package main

import (
	"fmt"
)

func main() {
	z := make([]int, 100000)

	var n int
	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)

		z[a] = z[a] + 1
	}

	sum := 0
	for i := 0; i < len(z); i++ {
		if z[i] != 0 {
			sum = sum + (i * z[i])
		}
	}

	var q int
	fmt.Scanf("%d", &q)

	ans := make([]int, q)
	var b1, b2 int
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &b1)
		fmt.Scanf("%d", &b2)

		if z[b1] > 0 {
			sum = sum - (b1 * z[b1] - b2 * z[b1])
			z[b2] = z[b2] + z[b1]
			z[b1] = 0
		}
		ans[i] = sum
	}

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}
